home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / CERTRQMA.AS_ / certrqma.asp
Encoding:
Text File  |  2003-02-21  |  75.7 KB  |  1,986 lines

  1. ∩╗┐<%@ CODEPAGE=65001 'UTF-8%>
  2. <%' certrqma.asp - (CERT)srv web - (R)e(Q)uest, (M)ore (A)dvanced
  3.   ' Copyright (C) Microsoft Corporation, 1998 - 1999 %>
  4. <!-- #include FILE=certsbrt.inc -->
  5. <!-- #include FILE=certdat.inc -->
  6. <% 
  7.     On Error Resume Next
  8.  
  9.     ' Exporting keys to a pvk file is only used by old code signing tools.
  10.     ' (This is different from exporting both cert and keys in a pfx file.)
  11.     ' Set this flag to true if you really need this functionality
  12.     bEnableExportKeyToFile = True
  13.  
  14.     Dim bFailed, nError
  15.     bFailed=False
  16.     nError = 0
  17.  
  18.     If "Enterprise"=sServerType And "IE"=sBrowser Then
  19.  
  20.             ' get CA exchange cert and save into this page
  21.  
  22.         Const CR_OUT_BASE64      =&H00000001
  23.         Const CR_PROP_CAEXCHGCERT=15
  24.         Const PROPTYPE_BINARY=3
  25.  
  26.         Set ICertRequest2=Server.CreateObject("CertificateAuthority.Request")
  27.         Public sCAExchangeCert
  28.         Dim sCertificate
  29.         sCertificate=ICertRequest2.GetCAProperty(sServerConfig, CR_PROP_CAEXCHGCERT, 0, PROPTYPE_BINARY, CR_OUT_BASE64)
  30.         sCAExchangeCert=FormatBigString(sCertificate, "    sCAExchange=sCAExchange & ")
  31.  
  32.         '&H800B0113, CERT_E_INVALID_POLICY, treat it as OK
  33.         If Err.Number<>0 And Err.Number <> &H800B0113 Then
  34.             ' CA may be down.
  35.             bFailed=True
  36.             nError=Err.Number
  37.         End If
  38.     End If
  39.  
  40.     '-----------------------------------------------------------------
  41.     ' Format the big string as a concatenated VB string, breaking at the embedded newlines
  42.     Function FormatBigString(sSource, sLinePrefix)
  43.         Dim sResult, bCharsLeft, nStartChar, nStopChar, chQuote
  44.         sResult=""
  45.         chQuote=chr(34)
  46.         bCharsLeft=True
  47.         nStopChar=1
  48.  
  49.         While (bCharsLeft)
  50.             nStartChar=nStopChar
  51.             nStopChar=InStr(nStopChar, sSource, vbNewLine)
  52.  
  53.             If (nStopChar>0) Then
  54.                 sResult=sResult & sLinePrefix & chQuote & Mid(sSource, nStartChar, nStopChar-nStartChar) & chQuote & " & vbNewLine"
  55.  
  56.                 If (nStopChar>=Len(sSource)-Len(vbNewLine)) Then
  57.                     bCharsLeft=False
  58.                 End If
  59.  
  60.             Else
  61.                 bCharsLeft=False
  62.             End if
  63.             sResult=sResult & vbNewLine
  64.             nStopChar=nStopChar+Len(vbNewLine)
  65.         Wend
  66.         FormatBigString=sResult
  67.     End Function
  68. %>
  69. <HTML>
  70. <Head>
  71.     <Meta HTTP-Equiv="Content-Type" Content="text/html; charset=UTF-8">
  72.     <Title>Microsoft Certificate Services</Title>
  73. </Head>
  74. <%If True=bFailed Then %>
  75. <Body BgColor=#FFFFFF Link=#0000FF VLink=#0000FF ALink=#0000FF><Font ID=locPageFont Face="Arial">
  76. <%Else%>
  77. <Body BgColor=#FFFFFF Link=#0000FF VLink=#0000FF ALink=#0000FF OnLoad="postLoad();"><Font ID=locPageFont Face="Arial">
  78. <%End If%>
  79.  
  80. <Table Border=0 CellSpacing=0 CellPadding=4 Width=100% BgColor=#008080>
  81. <TR>
  82.     <TD><Font Color=#FFFFFF><LocID ID=locMSCertSrv><Font Face="Arial" Size=-1><B><I>Microsoft</I></B> Certificate Services  --  <%=sServerDisplayName%>  </Font></LocID></Font></TD>
  83.     <TD ID=locHomeAlign Align=Right><A Href="/certsrv"><Font Color=#FFFFFF><LocID ID=locHomeLink><Font Face="Arial" Size=-1><B>Home</B></Font></LocID></Font></A></TD>
  84. </TR>
  85. </Table>
  86.  
  87. <%If True=bFailed Then %>
  88. <P ID=locPageTitle1><Font Color=#FF0000><B>Error</B></Font>
  89. <!-- Green HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#008080><Img Src="certspc.gif" Alt="" Height=2 Width=1></TD></TR></Table>
  90.  
  91. <P ID=locErrorMsg> An unexpected error has occurred:<BR><BR>
  92. <%If nError=&H800706BA Or nError=&H80070005 Then%>
  93.     <LocID ID=locSvcNotStarted>The Certification Authority Service has not been started.</LocID>
  94. <%ElseIf nError=&H800b0101 Then%> 
  95.     <LocID ID=locSvcNotValidDate>A required certificate is not within its validity period when verifying against the current system clock or the timestamp in the signed file.</LocID>
  96. <%Else%>
  97.     <%=ICertRequest.GetErrorMessageText(nError, CR_GEMT_HRESULT_STRING)%>
  98. <%End If%>
  99.  
  100. <%Else 'True<>bFailed%>
  101.  
  102. <Form Name=UIForm OnSubmit="goNext();return false;" Action="certlynx.asp" Method=Post>
  103. <Input Type=Hidden Name=SourcePage Value="certrqma">
  104.  
  105. <P ID=locPageTitle> <B> Advanced Certificate Request </B>
  106. <!-- Green HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#008080><Img Src="certspc.gif" Alt="" Height=2 Width=></TD></TR></Table>
  107.  
  108. <Span ID=spnFixTxt Style="display:none">
  109.     <Table Border=0 CellSpacing=0 CellPadding=4 Style="Color:#FF0000"><TR><TD ID=locBadCharError>
  110.         <I>Please correct the fields marked in <B>RED</B>.</I>
  111.         The e-mail address may contain the characters A-Z, a-z, 0-9, and some common symbols, but no extended characters.
  112.         The country/region field must be a two letter ISO 3166 country/region code.
  113.     </TD></TR></Table>
  114. </Span>
  115. <Span ID=spnErrorTxt Style="display:none">
  116.     <Table Border=0 CellSpacing=0 CellPadding=4 Style="Color:#FF0000">
  117.     <TR><TD ID=locErrMsgBasic>
  118.         <B>An error occurred</B> while creating the certificate request. 
  119.         Please verify that your CSP supports any settings you have made 
  120.         and that your input is valid.
  121.     </TD></TR><TR><TD>
  122.         <LocID ID=locErrorCause><B>Suggested cause:</B></LocID><BR>
  123.         <Span ID=spnErrorMsg></Span>
  124.     </TD></TR><TR>
  125.         <TD ID=locErrorNumber><Font Size=-2>Error: <Span ID=spnErrorNum></Span></Font></TD>
  126.     </TR>
  127.     </Table>
  128. </Span>
  129.  
  130.  
  131. <Table Border=0 CellSpacing=0 CellPadding=0>
  132.     <TR> <!-- establish column widths. -->
  133.         <TD Width=<%=L_LabelColWidth_Number%>></TD> <!-- label column, top border -->
  134.         <TD RowSpan=59 Width=4></TD>                <!-- label spacing column -->
  135.         <TD></TD>                                   <!-- field column -->
  136.     </TR>
  137.     
  138. <%If "Enterprise"=sServerType Then%>    <!-- Enterprise Options -->
  139.  
  140.     <TR>
  141.         <TD ID=locTemplateHead ColSpan=3><Font Size=-1><BR><Label For=lbCertTemplateID><locID ID=locTemplateHead><B>Certificate Template:</B></locID></Label></Font></TD>
  142.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  143.     </TR><TR><TD ColSpan=3 Height=6></TD>
  144.     </TR><TR><TD></TD>
  145.         <TD><Select Name=lbCertTemplate ID=lbCertTemplateID OnChange="handleTemplateChange();">
  146. <%
  147.     Dim nWriteTemplateResult
  148.     nWriteTemplateResult=WriteTemplateList() 
  149. %>
  150.         </Select></TD>
  151.     </TR>
  152.  
  153. <%End If '"Enterprise"=sServerType%>
  154.     <TR><TD ColSpan=3>
  155. <%If "Enterprise"=sServerType Then%>    <!-- Enterprise Options -->
  156. <Span ID=spnIDInfo Style="display:none">
  157. <%End If '"Enterprise"=sServerType%>
  158. <Table Border=0 CellSpacing=0 CellPadding=0>
  159.     <TR> <!-- establish column widths. -->
  160.         <TD Width=<%=L_LabelColWidth_Number%>></TD> <!-- label column, top border -->
  161.         <TD RowSpan=59 Width=4></TD>                <!-- label spacing column -->
  162.         <TD></TD>                                   <!-- field column -->
  163.     </TR>
  164.  
  165.  
  166.     <TR>
  167. <%If "StandAlone"=sServerType Then%>
  168.         <TD ID=locIdentHeadStandAlone ColSpan=3><Font Size=-1><BR><B>Identifying Information:</B></Font></TD>
  169.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  170. <%Else%>
  171.         <TD ID=locIdentHeadEnterprise ColSpan=3><Font Size=-1><BR><B>Identifying Information For Offline Template:</B></Font></TD>
  172.     </TR><!--<TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>-->
  173. <%End If%>
  174.     </TR><TR><TD ColSpan=3 Height=6></TD>
  175.     </TR><TR>
  176.         <TD ID=locNameAlign Align=Right><Span ID=spnNameLabel><LocID ID=locNameLabel><Font Size=-1>Name:</Font></LocID></Span></TD>
  177.         <TD><Input ID=locTbCommonName Type=Text MaxLength=64 Size=42 Name=tbCommonName></TD>
  178.     </TR><TR>
  179.         <TD ID=locEmailAlign Align=Right><Span ID=spnEmailLabel><LocID ID=locEmailLabel><Font Size=-1>E-Mail:</Font></LocID></Span></TD>
  180.         <TD><Input ID=locTbEmail Type=Text MaxLength=128 Size=42 Name=tbEmail></TD>
  181.     </TR><TR>
  182.         <TD Height=8></TD> <TD></TD>
  183.     </TR><TR>
  184.         <TD ID=locCompanyAlign Align=Right><Span ID=spnCompanyLabel><LocID ID=locOrgLabel><Font Size=-1>Company:</Font></LocID></Span></TD>
  185.         <TD><Input ID=locTbOrg Type=Text MaxLength=64 Size=42 Name=tbOrg Value="<%=sDefaultCompany%>"></TD>
  186.     </TR><TR>
  187.         <TD ID=locDepartmentAlign Align=Right><Span ID=spnDepartmentLabel><LocID ID=locOrgUnitLabel><Font Size=-1>Department:</Font></LocID></Span></TD>
  188.         <TD><Input ID=locTbOrgUnit Type=Text MaxLength=64 Size=42 Name=tbOrgUnit Value="<%=sDefaultOrgUnit%>"></TD>
  189.     </TR><TR>
  190.         <TD Height=8></TD> <TD></TD>
  191.     </TR><TR>
  192.         <TD ID=locCityAlign Align=Right><Span ID=spnCityLabel><LocID ID=locLocalityLabel><Font Size=-1>City:</Font></LocID></Span></TD>
  193.         <TD><Input ID=locTbLocality Type=Text MaxLength=128 Size=42 Name=tbLocality Value="<%=sDefaultLocality%>"></TD>
  194.     </TR><TR>
  195.         <TD ID=locStateAlign Align=Right><Span ID=spnStateLabel><LocID ID=locStateLabel><Font Size=-1>State:</Font></LocID></Span></TD>
  196.         <TD><Input ID=locTbState Type=Text MaxLength=128 Size=42 Name=tbState Value="<%=sDefaultState%>"></TD>
  197.     </TR><TR>
  198.         <TD ID=locCountryAlign Align=Right><Span ID=spnCountryLabel><LocID ID=locCountryLabel><Font Size=-1>Country/Region:</Font></LocID></Span></TD>
  199.         <TD><Input ID=locTbCountry Type=Text MaxLength=2 Size=2 Name=tbCountry Value="<%=sDefaultCountry%>"></TD> 
  200.     </TR>
  201.  
  202. </Table>
  203. <%If "Enterprise"=sServerType Then%>
  204. </Span>
  205. <%End If '"Enterprise"=sServerType%>
  206.     </TD></TR>
  207.  
  208. <%If "StandAlone"=sServerType Then%> <!-- Stand-Alone Options -->
  209.  
  210.     <TR>
  211.         <TD ID=locEKUHead ColSpan=3><Font Size=-1><BR><B>Type of Certificate Needed:</B></Font></TD>
  212.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  213.     </TR><TR><TD ColSpan=3 Height=6></TD>
  214.     </TR><TR><TD></TD>
  215.         <TD><Select Name=lbUsageOID OnChange="handleUsageOID(true);">
  216.             <Option ID=locCliAuthCert Selected Value="1.3.6.1.5.5.7.3.2"> Client Authentication Certificate
  217.             <Option ID=locEmailCert   Value="1.3.6.1.5.5.7.3.4"> E-Mail Protection Certificate
  218.             <Option ID=locSrvAuthCert Value="1.3.6.1.5.5.7.3.1"> Server Authentication Certificate
  219.             <Option ID=locCodeSgnCert Value="1.3.6.1.5.5.7.3.3"> Code Signing Certificate
  220.             <Option ID=locTimStmpCert Value="1.3.6.1.5.5.7.3.8"> Time Stamp Signing Certificate
  221.             <Option ID=locIPSecCert   Value="1.3.6.1.5.5.8.2.2"> IPSec Certificate
  222.             <Option ID=locUserEKUCert Value="**"> Other...
  223.         </Select></TD>
  224.     </TR>
  225.  
  226.     <TR><TD ID=locEkuAlign Align=Right><Span ID=spnEKUOther1 Style="display:none"><LocID ID=locUserEKULabel><Font Size=-1>OID:</Font></LocID></Span></TD>
  227.         <TD><Span ID=spnEKUOther2 Style="display:none"><Input ID=locTbEKUOther Type=Text Name=tbEKUOther Value="1.3.6.1.5.5.7.3."></Span></TD>
  228.     </TR>
  229.  
  230. <%End If%> <!-- common -->
  231.  
  232.     <TR>
  233.         <TD ID=locKeyOptHead ColSpan=3><Font Size=-1><BR><B>Key Options:</B></Font></TD>
  234.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  235.     </TR><TR><TD ColSpan=3 Height=6></TD>
  236.     </TR>
  237.  
  238.     <TR>
  239.         <TD></TD>
  240.         <TD><Font Size=-1>
  241.             <Input Type=Radio ID=rbKG1 Name=rbKeyGen Value="0" OnClick="handleKeyGen();" Checked><Label For=rbKG1 ID=locNewKeyLabel>Create new key set</Label>
  242.             <LocID ID=locSpc3>   <LocID>
  243.             <Input Type=Radio ID=rbKG2 Name=rbKeyGen Value="1" OnClick="handleKeyGen();"><Label For=rbKG2 ID=locExistKeyLabel>Use existing key set</Label>
  244.         </Font></TD>
  245.     </TR>
  246.  
  247.     <TR><TD ColSpan=3 Height=4></TD></TR>
  248.     <TR>
  249.         <TD ID=locCSPLabel Align=Right><Font Size=-1><Label For=lbCSPID><locID ID=locCSPLabel>CSP:</locID></Label></Font></TD>
  250.         <TD><Select Name=lbCSP ID=lbCSPID OnChange="handleCSPChange();">
  251.             <Option ID=locLoading>Loading...</Option>
  252.         </Select></TD>
  253.     </TR>
  254.     <TR ID=trBadCSPForKeySpec Style="display:none">
  255.         <TD></TD>
  256.         <TD BgColor=#FFFFE0><LocID ID=locBadCSPForKeySpec><Font Size=-1><Span ID=spnBadCSPForKeySpecMsg></Span></Font></LocID></TD>
  257.     </TR>
  258.  
  259.     <TR><TD ColSpan=3 Height=4></TD></TR>
  260.     <TR>
  261.         <TD ID=locKeyUsageLabel Align=Right><Font Size=-1>Key Usage:</Font></TD>
  262.         <TD><Font Size=-1>
  263.             <Span ID=spnKeyUsageKeyExchange><Input Type=Radio ID=rbKU1 Name=rbKeyUsage Value="0" Checked OnClick="handleKeyUsageChange(false);"><Label For=rbKU1 ID=locKUExch>Exchange</Label><LocID ID=locSpc1>   <LocID></Span>
  264.             <Span ID=spnKeyUsageSignature><Input Type=Radio ID=rbKU2 Name=rbKeyUsage Value="1" OnClick="handleKeyUsageChange(false);"><Label For=rbKU2 ID=locKUSig>Signature</Label><LocID ID=locSpc2>   <LocID></Span>
  265.             <Span ID=spnKeyUsageBoth><Input Type=Radio ID=rbKU3 Name=rbKeyUsage Value="2" OnClick="handleKeyUsageChange(false);"><Label For=rbKU3 ID=locKUBoth>Both</Label></Span></Font></TD>
  266.     </TR>
  267.  
  268.     <TR><TD ColSpan=3 Height=4></TD></TR>
  269.     <TR>
  270.         <TD ID=locKeySizeLabel Align=Right ><Font Size=-1><Label For=locTbKeySize><locID ID=locKeySizeLabel>Key Size:</locID></Label></Font></TD>
  271.         <TD><Table Border=0 CellPadding=0 CellSpacing=0>
  272.             <TR>
  273.                 <TD RowSpan=2><Input ID=locTbKeySize Type=Text Name=tbKeySize Value="0" MaxLength=5 Size=4 OnPropertyChange="handleKeySizeChange();"> </TD>
  274.                 <TD ID=locKeySizeMinLabel Align=Right><Font Size=-2>Min:</Font></TD>
  275.                 <TD ID=locKeySizeMin Align=Right><Font Size=-2><Span ID=spnKeySizeMin></Span></Font></TD>
  276.                 <TD ID=locKeySizeCommon RowSpan=2><Font Size=-2>  (common key sizes: <Span ID=spnKeySizeCommon></Span>)</Font></TD>
  277.             </TR><TR>
  278.                 <TD ID=locKeySizeMaxLabel Align=Right><Font Size=-2>Max:</Font></TD>
  279.                 <TD ID=locKeySizeMax Align=Right><Font Size=-2><Span ID=spnKeySizeMax></Span></Font></TD>
  280.             </TR>
  281.         </Table></TD>
  282.     </TR>
  283.     <TR ID=trKeySizeBad Style="display:none">
  284.         <TD></TD>
  285.         <TD BgColor=#FFFFE0><LocID ID=locKeySizeBad><Font Size=-1><Span ID=spnKeySizeBadMsg></Span></Font></LocID></TD>
  286.     </TR>
  287.     <TR ID=trKeySizeBadSpc Style="display:none"><TD ColSpan=3 Height=4></TD></TR>
  288.     <TR ID=trKeySizeWarn Style="display:none">
  289.         <TD></TD>
  290.         <TD BgColor=#FFFFE0><LocID ID=locKeySizeWarning><Font Size=-1><I>Warning: Large keys can take many hours to generate!</I></Font></LocID></TD>
  291.     </TR>
  292.     <TR ID=trKeyGenWarn Style="display:none">
  293.         <TD></TD>
  294.         <TD><LocID ID=locKeyGenWarning><Font Size=-1><I>A key of this size will be generated 
  295.         </I>only<I> if a key for the <BR> specified usage does not already exist in the specified 
  296.         container.</I></Font></LocID></TD>
  297.     </TR>
  298.  
  299.     <TR ID=trGenContNameSpc><TD ColSpan=3 Height=4></TD></TR>
  300.     <TR ID=trGenContName>
  301.         <TD></TD>
  302.         <TD><Font Size=-1>
  303.             <Input Type=Radio ID=rbGCN1 Name=rbGenContName Value="0" OnClick="handleGenContName();" Checked><Label For=rbGCN1 ID=locAutoContNameLabel>Automatic key container name</Label>
  304.             <LocID ID=locSpc4>   <LocID>
  305.             <Input Type=Radio ID=rbGCN2 Name=rbGenContName Value="1" OnClick="handleGenContName();"><Label For=rbGCN2 ID=locUserContNameLabel>User specified key container name</Label>
  306.         </Font></TD>
  307.     </TR>
  308.  
  309.     <TR ID=trContNameSpc><TD ColSpan=3 Height=4></TD></TR>
  310.     <TR ID=trContName Style="display:none">
  311.         <TD ID=locContainerNameLabel Align=Right><Font Size=-1>Container Name:</Font></TD>
  312.         <TD><Font Size=-1><Input ID=locTbContainerName Type=Text Name=tbContainerName Size=20></Font></TD>
  313.     </TR>
  314.  
  315.     <TR ID=trMarkExportSpc><TD ColSpan=3 Height=4></TD></TR>
  316.     <TR ID=trMarkExport><TD></TD>
  317.         <TD><Font Size=-1><Input Type=Checkbox Name=cbMarkKeyExportable ID=cbMarkKeyExportable OnClick="handleMarkExport(false);"><Label For=cbMarkKeyExportable ID=locMarkExportLabel>Mark keys as exportable</Label>
  318.         <%If bEnableExportKeyToFile Then%>
  319.         <Span ID=spnMarkKeyExportable Style="display:none">
  320.             <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><Input Type=Checkbox Name=cbExportKeys ID=cbExportKeys OnClick="handleExportKeys();"><Label For=cbExportKeys ID=locExportToFileLabel>Export keys to file</Label>
  321.             <Span ID=spnExportKeys Style="display:none">
  322.                 <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locExpFileNameLabel>Full path name:</LocID> <Input ID=locTbExportKeyFile Type=Text Name=tbExportKeyFile Size=20 Value="*.pvk">
  323.             </Span>
  324.         </Span>
  325.         <%End If%>
  326.         </Font></TD>
  327.     </TR>
  328.  
  329.     <TR ID=trStrongKeySpc><TD ColSpan=3 Height=4></TD></TR>
  330.     <TR ID=trStrongKey>
  331.         <TD></TD>
  332.         <TD><Font Size=-1><Input Type=Checkbox ID=cbStrongKey Name=cbStrongKey OnClick="handleStrongKeyAndLMStore(false);"><Label For=cbStrongKey ID=locStrongKeyLabel>Enable strong private key protection</Label></Font></TD>
  333.     </TR>
  334.  
  335.     <TR ID=trLMStoreSpc><TD ColSpan=3 Height=4></TD></TR>
  336.     <TR ID=trLMStore><TD></TD>
  337.         <TD><Font Size=-1><Input Type=Checkbox Name=cbLocalMachineStore ID=cbLocalMachineStore OnClick="handleStrongKeyAndLMStore(false);"><Label For=cbLocalMachineStore ID=locLMStoreLabel>Store certificate in the local computer certificate store</Label><BR>
  338.         <LocID ID=locAdminWarning><Img Src="certspc.gif" Alt="" Height=1 Width=25><I>Stores the certificate in the local computer store<BR>
  339.                   <Img Src="certspc.gif" Alt="" Height=1 Width=25>instead of in the user's certificate store. Does not<BR>
  340.                   <Img Src="certspc.gif" Alt="" Height=1 Width=25>install the root CA's certificate.  You must be an<BR>
  341.                   <Img Src="certspc.gif" Alt="" Height=1 Width=25>administrator to generate or use a key in the local<BR>
  342.                   <Img Src="certspc.gif" Alt="" Height=1 Width=25>machine store.</I></Font></LocID></TD>
  343.     </TR>
  344.  
  345.     <TR>
  346.         <TD ID=locAddOptHead ColSpan=3><Font Size=-1><BR><B>Additional Options:</B></Font></TD>
  347.     </TR><TR><TD ColSpan=3 Height=2 BgColor=#008080></TD>
  348.     </TR><TR><TD ColSpan=3 Height=3></TD>
  349.     </TR>
  350.  
  351.     <TR><TD ColSpan=3 Height=6></TD></TR>
  352.     <TR>
  353.         <TD ID=locRequestFormatLabel Align=Right><Font Size=-1>Request Format:</Font></TD>
  354.         <TD>
  355.         <Input Type=Radio ID=rbFormatCMC Name=rbRequestFormat Value="0" Checked><Label For=rbFormatCMC ID=locFormatCMCLabel>CMC</Label>
  356.         <LocID ID=locSpc5>   <LocID>
  357.         <Input Type=Radio ID=rbFormatPKCS10 Name=rbRequestFormat Value="1"><Label For=rbFormatPKCS10 ID=locFormatPKCS10Label>PKCS10</Label>
  358.         </TD>
  359.     </TR>
  360.     <TR><TD ColSpan=3 Height=4></TD></TR>
  361.  
  362.     <TR><TD ColSpan=3 Height=4></TD></TR>
  363.     <TR>
  364.         <TD ID=locHashAlgLabel Align=Right><Font Size=-1><Label For=lbHashAlgorithmID><locID ID=locHashAlgLabel>Hash Algorithm:</locID></Label></Font></TD>
  365.         <TD><Select Name=lbHashAlgorithm ID=lbHashAlgorithmID></Select></TD>
  366.     </TR>
  367.     <TR><TD></TD><TD ID=locHashAlgWarning><Font Size=-1><I>Only used to sign request.</I></Font></TD></TR>
  368.  
  369.     <TR><TD ColSpan=3 Height=8></TD></TR>
  370.     <TR><TD></TD>
  371.         <TD><Font Size=-1><Input Type=Checkbox Name=cbSaveRequest ID=cbSaveRequest OnClick="handleSaveReq();"><Label For=cbSaveRequest ID=locSaveReqLabel>Save request to a file</Label>
  372.         <Span ID=spnSaveRequest Style="display:none">
  373.             <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locReqFileNameLabel>Full path name:</LocID> <Input ID=locTbSaveReqFile Type=Text Name=tbSaveReqFile Size=20>
  374.             <BR><Img Src="certspc.gif" Alt="" Height=1 Width=25><LocID ID=locSaveReqWarning><B>This request will be saved and not submitted.</B></LocID>
  375.         </Span>
  376.         </Font></TD>
  377.     </TR>
  378.  
  379.     <TR><TD ColSpan=3 Height=6></TD>
  380.     </TR><TR>
  381.         <TD ID=locAttribLabel Align=Right><Font Size=-1><Span ID=spnSubmitAttrLable><Label For=locTaAttrib><locID ID=locAttribLabel>Attributes:</locID></Label></Span></Font></TD>
  382.         <TD><Span ID=spnSubmitAttrBox><TextArea ID=locTaAttrib Name=taAttrib Wrap=Off Rows=2 Cols=30></TextArea></SPan></TD>
  383.     </TR>
  384.  
  385.     <TR><TD ColSpan=3 Height=6></TD>
  386.     </TR><TR>
  387.         <TD ID=locFriendlyNameLabel Align=Right><Font Size=-1><Label For=locTbFriendlyName><locID ID=locFriendlyNameLabel>Friendly Name:</locID></Label></Font></TD>
  388.         <TD><Font Size=-1><Input ID=locTbFriendlyName Type=Text Name=tbFriendlyName Size=20></Font></TD>
  389.     </TR>
  390.  
  391.     <TR><TD ColSpan=3><Font Size=-1><BR></Font></TD></TR>
  392.     <TR><TD ColSpan=3 Height=2 BgColor=#008080></TD></TR>
  393.     <TR><TD ColSpan=3 Height=3></TD></TR>
  394.     <TR>
  395.         <TD></TD>
  396.         <TD ID=locSubmitAlign Align=Right>
  397.             <Input ID=locBtnSubmit Type=Submit Name=btnSubmit Value="Submit >" Style="width:.75in">
  398.             <Input ID=locBtnSave Type=Submit Name=btnSave Value="Save" Style="width:.75in; display:none">
  399.                  
  400.         </TD>
  401.     </TR>
  402.     <TR><TD ColSpan=3 Height=20></TD></TR>
  403.  
  404.  
  405. </Table>
  406. </P>
  407.  
  408.  
  409. <!-- Green HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#008080><Img Src="certspc.gif" Alt="" Height=2 Width=1></TD></TR></Table>
  410. <!-- White HR --><Table Border=0 CellSpacing=0 CellPadding=0 Width=100%><TR><TD BgColor=#FFFFFF><Img Src="certspc.gif" Alt="" Height=5 Width=1></TD></TR></Table>
  411.  
  412. </Form>
  413. </Font>
  414. <!-- ############################################################ -->
  415. <!-- End of standard text. Scripts follow  -->
  416.     
  417. <%bIncludeXEnroll=True%>
  418. <%bIncludeGetCspList=True%>
  419. <%bIncludeTemplateCode=True%>
  420. <%bIncludeCheckClientCode=True%>
  421. <!-- #include FILE=certsgcl.inc -->
  422.  
  423. <!-- This form we fill in and submit 'by hand'-->
  424. <Span Style="display:none">
  425. <Form Name=SubmittedData Action="certfnsh.asp" Method=Post>
  426.     <Input Type=Hidden Name=Mode>             <!-- used in request ('newreq'|'chkpnd') -->
  427.     <Input Type=Hidden Name=CertRequest>      <!-- used in request -->
  428.     <Input Type=Hidden Name=CertAttrib>       <!-- used in request -->
  429.     <Input Type=Hidden Name=FriendlyType>     <!-- used on pending -->
  430.     <Input Type=Hidden Name=ThumbPrint>       <!-- used on pending -->
  431.     <Input Type=Hidden Name=TargetStoreFlags> <!-- used on install ('0'|CSSLM)-->
  432.     <Input Type=Hidden Name=SaveCert>         <!-- used on install ('no'|'yes')-->
  433. </FORM>
  434. </Span>
  435.  
  436. <Script Language="JavaScript">
  437.  
  438.     //================================================================
  439.     // PAGE GLOBAL VARIABLES
  440.  
  441.     //----------------------------------------------------------------
  442.     // Strings to be localized
  443.     var L_CspLoadErrNoneFound_ErrorMessage="An unexpected error occurred while getting the CSP list:\nNo CSPs could be found!";
  444.     var L_CspLoadErrUnexpected_ErrorMessage="\"An unexpected error (\"+sErrorNumber+\") occurred while getting the CSP list.\"";
  445.     var L_SetKeySize_Message="\"Set key size to \"+nKeySize";
  446.     var L_WarningTemplateKeySize_Message="\"You have selected a certificate template that requires a minimum key size of \" + nKeySize + \"bits, which is larger than the selected CSP maximum.\\nPlease select a different CSP.\"";
  447.     var L_RecommendOneKeySize_Message="\"\"+nKeySize+\" is a bad key size. The closest valid key size is \"+sCloseBelow+\".\"";
  448.     var L_RecommendTwoKeySizes_Message="\"\"+nKeySize+\" is a bad key size. The closest valid key sizes are \"+sCloseBelow+\" and \"+sCloseAbove+\".\"";
  449.     var L_StillLoading_ErrorMessage="This page has not finished loading yet. Please wait a few seconds and try again.";
  450.     var L_KeySizeNotNumber_ErrorMessage="Please enter a number for the key size.";
  451.     var L_KeySizeBadNumber_ErrorMessage="\"Please enter a valid number for the key size. The key size must be\\nbetween \"+g_nCurKeySizeMin+\" and \"+g_nCurKeySizeMax+\", and be a multiple of \"+g_nCurKeySizeInc+\".\"";
  452.     var L_CSPNotSupportTemplateKeySpec_Message="\"You may have selected a CSP that does not support the key type defined in the template. Please modify the key type in the template or select either different CSP or certificate template.\"";
  453.     var L_TemplateKeySizeTooBig_ErrorMessage = "\"The certificate type you selected requires minimum key size of \" + g_nCurTemplateKeySizeMin + \".\\nIt is bigger than the maximum size of \" + g_nCurKeySizeMax + \".\\nPlease change the number or select a different CSP.\"";
  454.     var L_NoCntnrName_ErrorMessage="Please enter a key container name.";
  455.     var L_BadOid_ErrorMessage="Please enter a valid OID, or choose a predefined certificate type.\nMultiple OIDs must be separated with a comma.";
  456.     var L_NoExportFileName_ErrorMessage="Please enter a file name for exporting the keys.";
  457.     var L_NoSaveReqFileName_ErrorMessage="Please enter a file name for saving the request.";
  458.     var L_Generating_Message="Generating request...";
  459.     var L_UserEKUCert_Text="\"User-EKU (\"+sCertUsage+\") Certificate\"";
  460.     var L_RequestSaved_Message="Request saved to file.";
  461.     var L_Waiting_Message="Waiting for server response...";
  462.     var L_ErrNameUnknown_ErrorMessage="(unknown)";
  463.     var L_SugCauseNone_ErrorMessage="No suggestion.";
  464.     var L_SugCauseBadCSP_ErrorMessage="The CSP you chose was unable to process the request. Try a different CSP.";
  465.     var L_SugCauseKeysetFull_ErrorMessage="The security token does not have storage space available for an additional container.";
  466.     var L_SugCauseBadSetting2_ErrorMessage="The CSP you chose does not support one or more of the settings you have made, such as key size, key spec, hash algorithm, etc. Try using different settings or a different CSP.";
  467.     var L_SugCauseBadKeyContainer_ErrorMessage="Either the key container you specified does not exist, or the CSP you chose was unable to process the request. Enter the name of an existing key container; choose 'Create new keyset'; or try a different CSP.";
  468.     var L_SugCauseExistKeyContainer_ErrorMessage="The container you named already exists. When creating a new key, you must use a new container name.";
  469.     var L_SugCauseBadChar_ErrorMessage="You entered an invalid character. Report a bug, because this should have been caught in validation.";
  470.     var L_SugCauseBadHash_ErrorMessage="The hash algorithm you selected cannot be used for signing. Please select a different hash algorithm.";
  471.     var L_SugCauseNoFileName_ErrorMessage="You did not enter a file name.";
  472.     var L_SugCauseCryptArchivableNotSupp_ErrorMessage="The CSP you chose does not support the creation of keys which can be archived but not exported.";
  473.     var L_ErrNameNoFileName_ErrorMessage="(no file name)";
  474.     var L_SugCauseNotAdmin_ErrorMessage="You must be an administrator to generate a key in the local machine store.";
  475.     var L_ErrNamePermissionDenied_ErrorMessage="Permission Denied";
  476.     var L_SugCausePermissionToWrite_ErrorMessage = "You do not have write permission to save the file to the path";
  477.     var L_SugCauseBadFileName_ErrorMessage="The file name you specified is not a valid file name. Try a different file name.";
  478.     var L_SugCauseBadDrive_ErrorMessage="The drive you specified is not ready. Insert a disk in the drive or try a different file name.";
  479.     var L_SugCauseNoProfile_ErrorMessage="The profile for the user is a temporary profile.";
  480.     var L_SugCauseCAExSignerNotFound_ErrorMessage="A certificate chain could not be built to a trusted root authority.";
  481.     var L_SugCauseCAExNotTrusted_ErrorMessage="A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.";
  482.     var L_DownLevelClients_ErrorMessage="This error can be caused by requesting Key Archival for the new private key, which may not be supported on this platform.";
  483.     var L_SugCauseCancelled_ErrorMessage="The operation was canceled by the user.";
  484.     var L_SCARD_E_NOMEMORYMSG_ErrorMessage="Not enough memory available to complete this command.";
  485.     var L_SCARD_F_WAITEDTOOLONG_ErrorMessage="An internal consistency timer has expired.";
  486.     var L_SCARD_E_INSUFFICIENTBUFFER_ErrorMessage="The data buffer to receive returned data is too small for the returned data.";
  487.     var L_SCARD_E_UNKNOWNREADER_ErrorMessage="The specified reader name is not recognized.";
  488.     var L_SCARD_E_NOSMARTCARD_ErrorMessage="The operation requires a Smart Card, but no Smart Card is currently in the device.";
  489.     var L_SCARD_E_UNKNOWNCARD_ErrorMessage="The specified smart card name is not recognized.";
  490.     var L_SCARD_E_NOTREADY_ErrorMessage="The reader or smart card is not ready to accept commands.";
  491.     var L_SCARD_F_COMMERROR_ErrorMessage="An internal communications error has been detected.";
  492.     var L_SCARD_E_NOSERVICE_ErrorMessage="The Smart card resource manager is not running.";
  493.     var L_SCARD_E_SERVICESTOPPED_ErrorMessage="The Smart card resource manager has shut down.";
  494.     var L_SCARD_E_NOREADERSAVAILABLE_ErrorMessage="Cannot find a smart card reader.";
  495.     var L_SCARD_E_COMMDATALOST_ErrorMessage="A communications error with the smart card has been detected.  Retry the operation.";
  496.     var L_SCARD_E_NOKEYCONTAINER_ErrorMessage="The requested key container does not exist on the smart card.";
  497.     var L_SCARD_W_UNPOWEREDCARD_ErrorMessage="Power has been removed from the smart card, so that further communication is not possible.";
  498.     var L_SCARD_W_REMOVEDCARD_ErrorMessage="The smart card has been removed, so that further communication is not possible.";
  499.     var L_SCARD_W_WRONGCHV_ErrorMessage="The card cannot be accessed because the wrong PIN was presented.";
  500.     var L_SCARD_W_CHVBLOCKED_ErrorMessage="The card cannot be accessed because the maximum number of PIN entry attempts has been reached.";
  501.     var L_SCARD_W_EOF_ErrorMessage="The end of the smart card file has been reached.";
  502.     var L_SCARD_W_CANCELLEDBYUSER_ErrorMessage="The action was cancelled by the user.";
  503.     var L_SCARD_W_CARDNOTAUTHENTICATED_ErrorMessage="No PIN was presented to the smart card.";
  504.  
  505.     <%If "Enterprise"=sServerType Then%>
  506.     ;
  507.     var L_TemplateLoadErrNoneFound_ErrorMessage="No certificate templates could be found. You do not have permission to request a certificate from this CA, or an error occurred while accessing the Active Directory.";
  508.     var L_TemplateLoadErrUnexpected_ErrorMessage="\"An unexpected error (\"+sErrorNumber+\") occurred while getting the certificate template list.\"";
  509.     var L_TemplateCert_Text= "sFriendlyName+\" Certificate\"";
  510.     <%End If%>
  511.  
  512.     // IE is not ready until XEnroll has been loaded
  513.     var g_bOkToSubmit=false;
  514.     var g_bSubmitPending=false;
  515.  
  516.     // some constants defined in wincrypt.h:
  517.     var CRYPT_EXPORTABLE=1;
  518.     var CRYPT_USER_PROTECTED=2;
  519.     var CRYPT_MACHINE_KEYSET=0x20;
  520.     var AT_KEYEXCHANGE=1;
  521.     var AT_SIGNATURE=2;
  522.     var CERT_SYSTEM_STORE_LOCATION_SHIFT=16;
  523.     var CERT_SYSTEM_STORE_LOCAL_MACHINE_ID=2;
  524.     var CERT_SYSTEM_STORE_LOCAL_MACHINE=CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT;
  525.     var ALG_CLASS_ANY=0
  526.     var ALG_CLASS_SIGNATURE=1<<13;
  527.     var ALG_CLASS_HASH=4<<13;
  528.     var PROV_DSS=3;
  529.     var PROV_DSS_DH=13;
  530.     var PROV_DH_SCHANNEL=18;
  531.  
  532.  
  533.     // convenience constants, for readability
  534.     var KEY_USAGE_EXCH=0;
  535.     var KEY_USAGE_SIG=1;
  536.     var KEY_USAGE_BOTH=2;
  537.  
  538.     var XEKL_KEYSIZE_MIN=1;
  539.     var XEKL_KEYSIZE_MAX=2;
  540.     var XEKL_KEYSIZE_INC=3;
  541.     var XEKL_KEYSIZE_DEFAULT=4;
  542.     var XEKL_KEYSPEC_KEYX=1;
  543.     var XEKL_KEYSPEC_SIG=2;
  544.  
  545.     // defaults
  546.     var KEY_LEN_MIN_DEFAULT=384;
  547.     var KEY_LEN_MAX_DEFAULT=16384;
  548.     var KEY_LEN_MY_DEFAULT=1024;
  549.     var KEY_LEN_INC_DEFAULT=8;
  550.  
  551.     // for key size
  552.     var g_nCurKeySizeMax;
  553.     var g_nCurKeySizeMin;
  554.     var g_nCurKeySizeDefault;
  555.     var g_nCurKeySizeInc;
  556.     var g_bCSPUpdate;
  557.  
  558.     var g_nCurTemplateKeySizeMin = 0; //init to 0
  559.  
  560.     var XECR_PKCS10_V2_0=1;
  561.     var XECR_PKCS7=2;
  562.     var XECR_CMC=3;
  563.  
  564.     var XECT_EXTENSION_V1=1;
  565.     var XECT_EXTENSION_V2=2;
  566.  
  567.     //================================================================
  568.     // INITIALIZATION ROUTINES
  569.  
  570.     function removeV2KATemplate()
  571.     {
  572.         var CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL=0x00000001;
  573.         //downlevel machines, no V2 templates with KA
  574.         var nTemplateCount = document.UIForm.lbCertTemplate.length;
  575.         var n, sTemplate, sCTEOID;
  576.         for (n = nTemplateCount - 1; n > -1 ; --n)
  577.         {
  578.             sTemplate = document.UIForm.lbCertTemplate.options[n].value;
  579.             sCTEOID = getTemplateStringInfo(CTINFO_INDEX_EXTOID, sTemplate);
  580.             var lFlags=getTemplateValueInfo(CTINFO_INDEX_PRIVATEKEYFLAG, sTemplate);
  581.             if ("" != sCTEOID && 0x0 != (lFlags & CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL))
  582.             {
  583.                 //v2 template with KA
  584.                 document.UIForm.lbCertTemplate.options.remove(n);                
  585.             }
  586.         }
  587.     }
  588.  
  589.     //----------------------------------------------------------------
  590.     // This contains the functions we want executed immediately after load completes
  591.     function postLoad() {
  592.         // Load an XEnroll object into the page
  593.         loadXEnroll("postLoadPhase2()"); 
  594.         handleSaveReq();
  595.         handleCMCFormat();
  596.         <%If "Enterprise"=sServerType Then%>
  597.             if (!isClientAbleToCreateCMC())
  598.             {
  599.                 //downlevel machines
  600.                 removeV2KATemplate();
  601.             }
  602.         <%End If%>
  603.     }
  604.     function postLoadPhase2() {
  605.         // continued from above
  606.         var nResult;
  607.  
  608.         // get the CSP list
  609.         nResult=GetCSPList();
  610.         if (0!=nResult) {
  611.             handleLoadError(nResult, L_CspLoadErrNoneFound_ErrorMessage, L_CspLoadErrUnexpected_ErrorMessage);
  612.             return;
  613.         }
  614.  
  615.         <%If "StandAlone"<>sServerType And 0<>nWriteTemplateResult Then%>
  616.         handleLoadError(<%=nWriteTemplateResult%>, L_TemplateLoadErrNoneFound_ErrorMessage, L_TemplateLoadErrUnexpected_ErrorMessage);
  617.         return;
  618.         <%End If%>
  619.  
  620.         // Now we're ready to go
  621.         g_bOkToSubmit=true;
  622.  
  623.         <%If "Enterprise"=sServerType Then%>
  624.             handleTemplateChange();
  625.         <%Else%>
  626.             handleCSPChange();
  627.         <%End If%>
  628.         // dynamic styles are not preserved so
  629.         // make sure dynamic UI is updated after 'back'
  630.         handleKeyGen();
  631.         handleMarkExport(false);
  632.         handleExportKeys();
  633.         <%If "StandAlone"=sServerType Then%>
  634.         handleUsageOID(false);
  635.         <%End If%>
  636.     }
  637.  
  638.     //----------------------------------------------------------------
  639.     // handle errors from GetCSPList() and GetTemplateList()
  640.     function handleLoadError(nResult, sNoneFound, sUnexpected) {
  641.         if (-1==nResult) {
  642.             alert(sNoneFound);
  643.         } else {
  644.             var sErrorNumber="0x"+toHex(nResult);
  645.             alert(eval(sUnexpected));
  646.         }
  647.         disableAllControls();
  648.     }
  649.  
  650.     //================================================================
  651.     // PAGE MANAGEMENT ROUTINES
  652.  
  653.     <%If "StandAlone"=sServerType Then%>
  654.     //----------------------------------------------------------------
  655.     // handle the appearance of the text box when 'other...' is selected
  656.     function handleUsageOID(bFocus) {
  657.         if ("**"==document.UIForm.lbUsageOID.options[document.UIForm.lbUsageOID.selectedIndex].value) {
  658.             spnEKUOther1.style.display='';
  659.             spnEKUOther2.style.display='';
  660.             if (bFocus) {
  661.                 document.UIForm.lbUsageOID.blur();
  662.                 document.UIForm.tbEKUOther.select();
  663.                 document.UIForm.tbEKUOther.focus();
  664.             }
  665.         } else {
  666.             spnEKUOther1.style.display='none';
  667.             spnEKUOther2.style.display='none';
  668.         }
  669.     }
  670.     <%End If%>
  671.  
  672.     <%If "Enterprise"=sServerType Then%>
  673.     //----------------------------------------------------------------
  674.  
  675.  
  676.         function getTemplateValueInfo(nIndex, sTemplate)
  677.     {
  678.         var sValue=getTemplateStringInfo(nIndex, sTemplate);
  679.         return parseInt(sValue);
  680.     }
  681.  
  682.     // handle a change in the current template
  683.     function isDNNeeded() {
  684.         var sValue=getTemplateStringInfo(CTINFO_INDEX_OFFLINE, null);
  685.         if ("O"==sValue)
  686.         {
  687.             //offline template needs DN
  688.             return true;
  689.         }
  690.  
  691.         //check template subject flag
  692.         var lSubjectFlag = getTemplateValueInfo(CTINFO_INDEX_SUBJECTFLAG, null);
  693.         var CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT=0x00000001;
  694.         return (0x0 != (lSubjectFlag & CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT));
  695.     }
  696.  
  697.         function isTemplateKeyArchival()
  698.         {
  699.         var CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL=0x00000001;
  700.         var lFlags=getTemplateValueInfo(CTINFO_INDEX_PRIVATEKEYFLAG, null);
  701.         return (0x0 != (lFlags & CT_FLAG_ALLOW_PRIVATE_KEY_ARCHIVAL));
  702.     }
  703.  
  704.         function isSMimeCapabilities()
  705.         {
  706.         var CT_FLAG_INCLUDE_SYMMETRIC_ALGORITHMS=0x00000001;
  707.         var lFlags=getTemplateValueInfo(CTINFO_INDEX_ENROLLFLAG, null);
  708.         return (0x0 != (lFlags & CT_FLAG_INCLUDE_SYMMETRIC_ALGORITHMS));
  709.     }
  710.  
  711.     function getTemplateMinKeySize()
  712.     {
  713.         var lKeyFlags = getTemplateValueInfo(CTINFO_INDEX_KEYFLAG, null);
  714.         return (lKeyFlags & 0xFFFF0000) >> 16;
  715.     }
  716.  
  717.     function updateCSPList()
  718.     {
  719.                 //get csp list separated from template data
  720.                 var sCSPList = getTemplateStringInfo(CTINFO_INDEX_CSPLIST, null);
  721.         if ("" != sCSPList)
  722.         {
  723.             updateCSPListFromStrings(sCSPList);
  724.         }
  725.         else
  726.         {
  727.             //remove current csps from list
  728.             //strange reasons this remove code can't be in GetCSPList
  729.             var n;
  730.             var nCSP = document.UIForm.lbCSP.length;
  731.             for (n = 0; n < nCSP-1; ++n)
  732.             {
  733.                 document.UIForm.lbCSP.remove(0);
  734.             }
  735.             GetCSPList();
  736.         }
  737.     }
  738.  
  739.     //----------------------------------------------------------------
  740.     // handle a change in the current template
  741.     function handleTemplateChange()
  742.     {
  743.         if (false==isDNNeeded()) {
  744.             spnIDInfo.style.display="none";
  745.         } else {
  746.             spnIDInfo.style.display="";
  747.         }
  748.  
  749.                 //update csp list from the template
  750.                 updateCSPList();
  751.         handleCSPChange();
  752.  
  753.         //handle key spec
  754.                 var lKeySpec = getTemplateValueInfo(CTINFO_INDEX_KEYSPEC, null);
  755.                 var fDisabled = true;
  756.                 if ((0x0 != (AT_KEYEXCHANGE & lKeySpec)) &&
  757.                     (0x0 != (AT_SIGNATURE & lKeySpec)) )
  758.                 {
  759.             document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked=true;
  760.                 }
  761.                 else if (0x0 != (AT_KEYEXCHANGE & lKeySpec))
  762.                 {
  763.             document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked=true;
  764.                 }
  765.                 else if (0x0 != (AT_SIGNATURE & lKeySpec))
  766.                 {
  767.             document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked=true;
  768.                 }
  769.                 else
  770.                 {
  771.             document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked=true;
  772.                         fDisabled = false;
  773.                 }
  774.                 document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].disabled=fDisabled;
  775.                 document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].disabled=fDisabled;
  776.                 document.UIForm.rbKeyUsage[KEY_USAGE_SIG].disabled=fDisabled;
  777.  
  778.         //update exportable control
  779.         var lPrivateKeyFlags = getTemplateValueInfo(CTINFO_INDEX_PRIVATEKEYFLAG, null);
  780.         var CT_FLAG_EXPORTABLE_KEY = 0x10;
  781.         document.UIForm.cbMarkKeyExportable.checked = (0x0 != (lPrivateKeyFlags & CT_FLAG_EXPORTABLE_KEY));
  782.         handleMarkExport(true);
  783.  
  784.         //update strong key protection control
  785.                 var CT_FLAG_STRONG_KEY_PROTECTION_REQUIRED = 0x20; 
  786.                 document.UIForm.cbStrongKey.checked = (0x0 != (lPrivateKeyFlags & CT_FLAG_STRONG_KEY_PROTECTION_REQUIRED));
  787.                 handleStrongKeyAndLMStore(true);
  788.  
  789.         //update template min key size
  790.         g_nCurTemplateKeySizeMin = getTemplateMinKeySize();
  791.  
  792.                 //update key size
  793.         handleKeyUsageChange(false);
  794.  
  795.         //update CMC related
  796.         handleCMCFormat();
  797.  
  798.         var lRASignatures = getTemplateValueInfo(CTINFO_INDEX_RASIGNATURE, null);
  799.         var fSave = 0 < lRASignatures;
  800.         //enforce save to file, can't submit if signing
  801.         document.UIForm.cbSaveRequest.checked = fSave;
  802.         document.UIForm.cbSaveRequest.disabled = fSave;
  803.         handleSaveReq();
  804.  
  805.     }
  806.     <%End If%>
  807.  
  808.     //----------------------------------------------------------------
  809.     // handle a change in the current CSP
  810.     function handleCSPChange() {
  811.  
  812.         if (0 == document.UIForm.lbCSP.length)
  813.         {
  814.             //no csp, disable submit button
  815.             document.UIForm.btnSubmit.disabled = true;
  816.             return;
  817.         }
  818.         else
  819.         {
  820.             document.UIForm.btnSubmit.disabled = false;
  821.         }
  822.         var nCSPIndex=document.UIForm.lbCSP.selectedIndex;
  823.         XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  824.         var nProvType=document.UIForm.lbCSP.options[nCSPIndex].value;
  825.         XEnroll.ProviderType=nProvType;
  826.         <%If "Enterprise"=sServerType Then%>
  827.                 var nTemplateKeySpec = getTemplateValueInfo(CTINFO_INDEX_KEYSPEC, null);
  828.         <%End If%>
  829.  
  830.         // update the key spec options. If we support both, default to key exchange
  831.         var nSupportedKeyUsages=XEnroll.GetSupportedKeySpec();
  832.         if (0==nSupportedKeyUsages) {
  833.             nSupportedKeyUsages=AT_SIGNATURE | AT_KEYEXCHANGE;
  834.         }
  835.  
  836.         <%If "Enterprise"=sServerType Then%>
  837.         if (0==nTemplateKeySpec) {
  838.             nTemplateKeySpec=AT_SIGNATURE | AT_KEYEXCHANGE;
  839.         }
  840.         nSupportedKeyUsages = nTemplateKeySpec & nSupportedKeyUsages;
  841.         <%End If%>
  842.  
  843.         if (PROV_DSS==nProvType || PROV_DSS_DH==nProvType || PROV_DH_SCHANNEL==nProvType) {
  844.             nSupportedKeyUsages=AT_SIGNATURE;
  845.         }
  846.  
  847.         if (0 == nSupportedKeyUsages)
  848.         {
  849.             spnBadCSPForKeySpecMsg.innerHTML=eval(L_CSPNotSupportTemplateKeySpec_Message);
  850.             trBadCSPForKeySpec.style.display="";
  851.         } else {
  852.             trBadCSPForKeySpec.style.display="none";
  853.         }
  854.  
  855.         if (nSupportedKeyUsages&AT_SIGNATURE) {
  856.             spnKeyUsageSignature.style.display="";
  857.             document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked=true;
  858.         } else {
  859.             spnKeyUsageSignature.style.display="none";
  860.         }
  861.  
  862.         if (nSupportedKeyUsages&AT_KEYEXCHANGE) {
  863.             spnKeyUsageKeyExchange.style.display="";
  864.             document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked=true;
  865.         } else {
  866.             spnKeyUsageKeyExchange.style.display="none";
  867.         }
  868.  
  869.         if ((AT_SIGNATURE|AT_KEYEXCHANGE)==nSupportedKeyUsages) {
  870.             spnKeyUsageBoth.style.display="";
  871.             document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked=true;
  872.         } else {
  873.             spnKeyUsageBoth.style.display="none";
  874.         }
  875.  
  876.         handleKeyUsageChange(true);
  877.         UpdateHashAlgList(nProvType);
  878.     }
  879.  
  880.     //----------------------------------------------------------------
  881.     // two cases invoke handleKeyUsageChange:
  882.         // 1) csp selection change
  883.         // 2) exchange vs. signature change
  884.     function handleKeyUsageChange(bCSPChange) {
  885.         // get the min, max, and default length from the CSP
  886.         var bExchange=document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked || document.UIForm.rbKeyUsage[KEY_USAGE_BOTH].checked ;
  887.  
  888.         g_nCurKeySizeMax=MyGetKeyLen(XEKL_KEYSIZE_MAX, bExchange);
  889.         g_nCurKeySizeMin=MyGetKeyLen(XEKL_KEYSIZE_MIN, bExchange);
  890.         
  891.         <%If "Enterprise"=sServerType Then%>
  892.         if (0 != g_nCurTemplateKeySizeMin)
  893.         {
  894.             g_nCurKeySizeMin=Math.max(g_nCurKeySizeMin, g_nCurTemplateKeySizeMin);
  895.         }
  896.         <%End If%>
  897.         g_nCurKeySizeDefault=MyGetKeyLen(XEKL_KEYSIZE_DEFAULT, bExchange);
  898.         g_nCurKeySizeInc=MyGetKeyLen(XEKL_KEYSIZE_INC, bExchange);
  899.  
  900.                 // set to default lenth
  901.                 if ("0"==document.UIForm.tbKeySize.value || true == bCSPChange)
  902.                 {
  903.                     //"0" likely init load or typed in, not bad go default
  904.                     // or csp changed, set to default length
  905.                     document.UIForm.tbKeySize.value = g_nCurKeySizeDefault;
  906.                 }
  907.  
  908.         // show the min and max
  909.         spnKeySizeMin.innerText=g_nCurKeySizeMin;
  910.         spnKeySizeMax.innerText=g_nCurKeySizeMax;
  911.  
  912.         // keep the key size in bounds
  913.         var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  914.         if (isNaN(nKeySize) || nKeySize>g_nCurKeySizeMax) {
  915.             document.UIForm.tbKeySize.value=g_nCurKeySizeMax;
  916.         } else if (nKeySize<g_nCurKeySizeMin) { //>
  917.             document.UIForm.tbKeySize.value=g_nCurKeySizeMin;
  918.         }
  919.  
  920.         // update list of valid common key sizes
  921.         var nPowerSize=128;
  922.         var sCommonKeys="";
  923.         while (nPowerSize<g_nCurKeySizeMin) { //>
  924.             nPowerSize*=2;
  925.         }
  926.         while (nPowerSize<=g_nCurKeySizeMax) {
  927.             sCommonKeys+=getKeySizeLinkHtmlString(nPowerSize)+" ";
  928.             nPowerSize*=2;
  929.         }
  930.         spnKeySizeCommon.innerHTML=sCommonKeys;
  931.         handleKeySizeChange();
  932.     }
  933.  
  934.     //----------------------------------------------------------------
  935.     function getKeySizeLinkHtmlString(nKeySize) {
  936.         return "<Span tabindex=0 Style=\"cursor:hand; color:#0000FF; text-decoration:underline;\""
  937.             +" OnContextMenu=\"return false;\""
  938.             +" OnMouseOver=\"window.status='"+eval(L_SetKeySize_Message)+"';return true;\""
  939.             +" OnMouseOut=\"window.status='';return true;\""
  940.             +" OnMouseUp=\"window.status='"+eval(L_SetKeySize_Message)+"';return true;\""
  941.             +" OnKeyDown=\"if (13==event.keyCode) {document.UIForm.tbKeySize.value='"+nKeySize+"';blur();return false;} else if (9==event.keyCode) {return true;};return false;\""
  942.             +" OnClick=\"document.UIForm.tbKeySize.value='"+nKeySize+"';blur();return false;\">"
  943.             +nKeySize+"</Span>";
  944.     }
  945.  
  946.     //----------------------------------------------------------------
  947.     // morphing routine
  948.     function handleSaveReq() {
  949.         if (document.UIForm.cbSaveRequest.checked) {
  950.             spnSaveRequest.style.display='';
  951.             document.UIForm.btnSubmit.style.display='none';
  952.             document.UIForm.btnSave.style.display='';
  953.             spnSubmitAttrLable.style.display='none';
  954.             spnSubmitAttrBox.style.display='none';
  955.         } else {
  956.             spnSaveRequest.style.display='none';
  957.             document.UIForm.btnSubmit.style.display='';
  958.             document.UIForm.btnSave.style.display='none';
  959.             spnSubmitAttrLable.style.display='';
  960.             spnSubmitAttrBox.style.display='';
  961.         }
  962.     }
  963.  
  964.     //----------------------------------------------------------------
  965.     // morphing routine
  966.     function handleMarkExport(fFromTemplate) {
  967.         <%If bEnableExportKeyToFile Then%>
  968.         if (document.UIForm.cbMarkKeyExportable.checked) {
  969.             spnMarkKeyExportable.style.display='';
  970.             document.UIForm.cbMarkKeyExportable.disabled = false;
  971.         } else {
  972.             spnMarkKeyExportable.style.display='none';
  973.             if (fFromTemplate)
  974.             {
  975.                 //disable it to enforce template non-exportable
  976.                 document.UIForm.cbMarkKeyExportable.disabled = true;
  977.             }
  978.             else
  979.             {
  980.                 //enable
  981.                 document.UIForm.cbMarkKeyExportable.disabled = false;
  982.             }
  983.         }
  984.         <%End If%>
  985.     }
  986.  
  987.     //----------------------------------------------------------------
  988.     // morphing routine
  989.     function handleExportKeys() {
  990.         <%If bEnableExportKeyToFile Then%>
  991.         if (document.UIForm.cbExportKeys.checked) {
  992.             spnExportKeys.style.display='';
  993.         } else {
  994.             spnExportKeys.style.display='none';
  995.         }
  996.         <%End If%>
  997.     }
  998.  
  999.     //----------------------------------------------------------------
  1000.     // morphing routine
  1001.     function handleKeyGen() {
  1002.         if (document.UIForm.rbKeyGen[0].checked) {
  1003.             // create new keyset
  1004.             trGenContName.style.display='';
  1005.             trGenContNameSpc.style.display='';
  1006.             trKeyGenWarn.style.display='none';
  1007.  
  1008.             handleGenContName();
  1009.             <%If "Enterprise"=sServerType Then%>
  1010.                 handleTemplateChange();
  1011.             <%Else%>
  1012.                 handleStrongKeyAndLMStore(false);
  1013.             <%End If%>
  1014.  
  1015.             trMarkExport.style.display='';
  1016.             trMarkExportSpc.style.display='';
  1017.         } else {
  1018.             // Use existing key set
  1019.             trGenContName.style.display='none';
  1020.             trGenContNameSpc.style.display='none';
  1021.             trKeyGenWarn.style.display='';
  1022.  
  1023.             handleGenContName();
  1024.             handleStrongKeyAndLMStore(false);
  1025.  
  1026.             document.UIForm.cbMarkKeyExportable.checked=false;
  1027.             trMarkExport.style.display='none';
  1028.             trMarkExportSpc.style.display='none';
  1029.          }
  1030.     }
  1031.  
  1032.     //----------------------------------------------------------------
  1033.     // morphing routine
  1034.     function handleGenContName() {
  1035.         if (document.UIForm.rbGenContName[0].checked && document.UIForm.rbKeyGen[0].checked) {
  1036.             trContName.style.display='none';
  1037.             trContNameSpc.style.display='none';
  1038.         } else {
  1039.             trContName.style.display='';
  1040.             trContNameSpc.style.display='';
  1041.         }
  1042.     }
  1043.  
  1044.     //----------------------------------------------------------------
  1045.     // morphing routine
  1046.     function handleSetContainer() {
  1047.         if (document.UIForm.cbSetContainer.checked) {
  1048.             spnNewContainer.style.display='';
  1049.         } else {
  1050.             spnNewContainer.style.display='none';
  1051.         }
  1052.     }
  1053.  
  1054.     //----------------------------------------------------------------
  1055.     // morphing routine
  1056.     function handleKeySizeChange() {
  1057.         var sKeySize = document.UIForm.tbKeySize.value;
  1058.         if (0 == sKeySize.indexOf("0"))
  1059.         {
  1060.             //first digit is 0, wipe it out
  1061.             document.UIForm.tbKeySize.value = "";
  1062.             return;
  1063.         }
  1064.         var nKeySize=parseInt(sKeySize);
  1065.         if (isNaN(nKeySize)) {
  1066.             nKeySize=0;
  1067.         }
  1068.         if (nKeySize>2048) {
  1069.             trKeySizeWarn.style.display='';
  1070.         } else {
  1071.             trKeySizeWarn.style.display='none';
  1072.         }
  1073.         if (nKeySize<g_nCurKeySizeMin || nKeySize>g_nCurKeySizeMax || 0!=nKeySize%g_nCurKeySizeInc) {
  1074.             // clamp the current key size to be within the range
  1075.             var nCloseBelow=nKeySize;
  1076.             if (nCloseBelow<g_nCurKeySizeMin) { //>
  1077.                 nCloseBelow=g_nCurKeySizeMin;
  1078.             } else if (nCloseBelow>g_nCurKeySizeMax) { 
  1079.                 nCloseBelow=g_nCurKeySizeMax;
  1080.             }
  1081.             var nCloseAbove=nCloseBelow;
  1082.             // find closest values above and below
  1083.             nCloseBelow-=nCloseBelow%g_nCurKeySizeInc;
  1084.             nCloseAbove+=(g_nCurKeySizeInc-nCloseAbove%g_nCurKeySizeInc)%g_nCurKeySizeInc;
  1085.             var sCloseAbove=getKeySizeLinkHtmlString(nCloseAbove);
  1086.             var sCloseBelow=getKeySizeLinkHtmlString(nCloseBelow);
  1087.             if (g_nCurKeySizeMax < g_nCurTemplateKeySizeMin) {
  1088.                 spnKeySizeBadMsg.innerHTML=eval(L_WarningTemplateKeySize_Message);
  1089.             } else if (nCloseAbove==nCloseBelow) {
  1090.                 spnKeySizeBadMsg.innerHTML=eval(L_RecommendOneKeySize_Message);
  1091.             } else {
  1092.                 spnKeySizeBadMsg.innerHTML=eval(L_RecommendTwoKeySizes_Message);
  1093.             }
  1094.             trKeySizeBad.style.display="";
  1095.             trKeySizeBadSpc.style.display="";
  1096.         } else {
  1097.             trKeySizeBad.style.display="none";
  1098.             trKeySizeBadSpc.style.display="none";
  1099.         }
  1100.     }
  1101.  
  1102.     //----------------------------------------------------------------
  1103.     // morphing routine
  1104.     function handleStrongKeyAndLMStore(fFromTemplate) {
  1105.                 // If we took the value from the template, and the checkbox is checked, the disable it
  1106.                 if (document.UIForm.cbStrongKey.checked && fFromTemplate) { 
  1107.                     //disable it to enforce template non-exportable
  1108.                     document.UIForm.cbStrongKey.disabled = true;
  1109.                 } else { 
  1110.                     document.UIForm.cbStrongKey.disabled = false    ;
  1111.                 }
  1112.  
  1113.         if (document.UIForm.cbStrongKey.checked && document.UIForm.rbKeyGen[0].checked) {
  1114.             trLMStoreSpc.style.display='none';
  1115.             trLMStore.style.display='none';
  1116.             document.UIForm.cbLocalMachineStore.checked=false;
  1117.         } else {
  1118.             trLMStoreSpc.style.display='';
  1119.             trLMStore.style.display='';
  1120.         }
  1121.  
  1122.         if (document.UIForm.cbLocalMachineStore.checked || !document.UIForm.rbKeyGen[0].checked) {
  1123.             trStrongKeySpc.style.display='none';
  1124.             trStrongKey.style.display='none';
  1125.             document.UIForm.cbStrongKey.checked=false;
  1126.         } else {
  1127.             trStrongKeySpc.style.display='';
  1128.             trStrongKey.style.display='';
  1129.         }
  1130.     }
  1131.     //----------------------------------------------------------------
  1132.     // handle CMC Format
  1133.     function handleCMCFormat() {
  1134.         if (isClientAbleToCreateCMC())
  1135.         {
  1136.             <%If "Enterprise"=sServerType Then%>
  1137.             //change request format controls
  1138.             if (isTemplateKeyArchival())
  1139.             {
  1140.                 //enforce CMC
  1141.                 document.UIForm.rbRequestFormat[0].disabled=true;
  1142.                 document.UIForm.rbRequestFormat[0].checked=true;
  1143.                 document.UIForm.rbRequestFormat[1].disabled=true;
  1144.             }
  1145.             else
  1146.             {
  1147.                 document.UIForm.rbRequestFormat[0].disabled=false;
  1148.                 document.UIForm.rbRequestFormat[1].disabled=false;
  1149.             }
  1150.             <%End If%>
  1151.         }
  1152.         else
  1153.         {
  1154.             //no cmc, disable it, only pkcs10
  1155.             document.UIForm.rbRequestFormat[0].disabled=true;
  1156.             document.UIForm.rbRequestFormat[1].disabled=true;
  1157.             document.UIForm.rbRequestFormat[1].checked=true;
  1158.         }
  1159.     }
  1160.  
  1161.     //================================================================
  1162.     // SUBMIT ROUTINES
  1163.  
  1164.     //----------------------------------------------------------------
  1165.     // determine what to do when the submit button is pressed
  1166.     function goNext() {
  1167.         if (false==g_bOkToSubmit) {
  1168.             alert(L_StillLoading_ErrorMessage);
  1169.         } else if (true==g_bSubmitPending) {
  1170.             // ignore, because we are already prcessing a request.
  1171.         } else {
  1172.             SubmitRequest();
  1173.         }
  1174.     }
  1175.         
  1176.     //----------------------------------------------------------------
  1177.     // check for invalid characters and empty strings
  1178.     function isValidIA5String(sSource) {
  1179.         var nIndex;
  1180.         for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  1181.             if (sSource.charCodeAt(nIndex)>127) {  // NOTE: this is better, but not compatible with old browsers.
  1182.                 return false;
  1183.             }
  1184.         };
  1185.         return true;
  1186.     }
  1187.  
  1188.     //----------------------------------------------------------------
  1189.     // check for invalid characters
  1190.     function isValidCountryField(tbCountry) {
  1191.         tbCountry.value=tbCountry.value.toUpperCase();
  1192.         var sSource=tbCountry.value;
  1193.         var nIndex, ch;
  1194.         if (0!=sSource.length && 2!=sSource.length) {
  1195.             return false;
  1196.         }
  1197.         for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  1198.             ch=sSource.charAt(nIndex)
  1199.             if (ch<"A" || ch>"Z") {
  1200.                 return false;
  1201.             }
  1202.         };
  1203.         return true;
  1204.     }
  1205.  
  1206.     //----------------------------------------------------------------
  1207.     // check for invalid characters in an OID
  1208.     function isValidOid(sSource) {
  1209.         var nIndex, ch;
  1210.         if (0==sSource.length) {
  1211.             return true;
  1212.         }
  1213.         for (nIndex=sSource.length-1; nIndex>=0; nIndex--) {
  1214.             ch=sSource.charAt(nIndex)
  1215.             if (ch!="." && ch!="," && (ch<"0" || ch>"9")) {
  1216.                 return false;
  1217.             }
  1218.         }
  1219.         return true;
  1220.     }
  1221.  
  1222.     //----------------------------------------------------------------
  1223.     // set a label to normal style
  1224.     function markLabelNormal(spn) {
  1225.         spn.style.color="#000000";
  1226.         spn.style.fontWeight='normal';
  1227.     }
  1228.  
  1229.     //----------------------------------------------------------------
  1230.     // set a label to error state
  1231.     function markLabelError(spn) {
  1232.         spn.style.color='#FF0000';
  1233.         spn.style.fontWeight='bold';
  1234.     }
  1235.  
  1236.     //----------------------------------------------------------------
  1237.     // check that the form has data in it
  1238.     function validateRequest() {
  1239.         markLabelNormal(spnNameLabel);
  1240.         markLabelNormal(spnEmailLabel);
  1241.         markLabelNormal(spnCompanyLabel);
  1242.         markLabelNormal(spnDepartmentLabel);
  1243.         markLabelNormal(spnCityLabel);
  1244.         markLabelNormal(spnStateLabel);
  1245.         markLabelNormal(spnCountryLabel);
  1246.         
  1247.         var bOK=true;
  1248.  
  1249.         <%If "Enterprise"=sServerType Then%>    
  1250.         if (true==isDNNeeded()) {
  1251.         <%End If%>
  1252.             var fldFocusMe=null;
  1253.             if (false==isValidCountryField(document.UIForm.tbCountry)) {
  1254.                 bOK=false;
  1255.                 fldFocusMe=document.UIForm.tbCountry;
  1256.                 markLabelError(spnCountryLabel);
  1257.             }
  1258.             // document.UIForm.tbState.value OK
  1259.             // document.UIForm.tbLocality.value OK
  1260.             // document.UIForm.tbOrgUnit.value OK
  1261.             // document.UIForm.tbOrg.value OK
  1262.             if (false==isValidIA5String(document.UIForm.tbEmail.value))
  1263.             {
  1264.                 bOK=false;
  1265.                 fldFocusMe=document.UIForm.tbEmail;
  1266.                 markLabelError(spnEmailLabel);
  1267.             }
  1268.             <%If "StandAlone"=sServerType Then%>
  1269.             if ("1.3.6.1.5.5.7.3.4"==document.UIForm.lbUsageOID.value && ""==document.UIForm.tbEmail.value)
  1270.             {
  1271.                 bOK=false;
  1272.                 fldFocusMe=document.UIForm.tbEmail;
  1273.                 markLabelError(spnEmailLabel);
  1274.             }
  1275.             if (""==document.UIForm.tbCommonName.value)
  1276.             {
  1277.                 bOK=false;
  1278.                 fldFocusMe=document.UIForm.tbCommonName;
  1279.                 markLabelError(spnNameLabel);
  1280.             }
  1281.             <%End If%>
  1282.  
  1283.             if (false==bOK) {
  1284.                 spnFixTxt.style.display='';
  1285.                 window.scrollTo(0,0);
  1286.                 fldFocusMe.focus();
  1287.             }
  1288.         <%If "Enterprise"=sServerType Then%>    
  1289.         } // <- End if offline template
  1290.         <%End If%>
  1291.  
  1292.         <%If "StandAlone"=sServerType Then%>
  1293.         // Check the OID field
  1294.         if (true==bOK) {
  1295.             if ("**"==document.UIForm.lbUsageOID.options[document.UIForm.lbUsageOID.selectedIndex].value
  1296.                 && false==isValidOid(document.UIForm.tbEKUOther.value)) {
  1297.                 alert(L_BadOid_ErrorMessage);
  1298.                 document.UIForm.tbEKUOther.focus();
  1299.                 bOK=false;
  1300.             }
  1301.         }
  1302.         <%End If%>
  1303.  
  1304.         // Check the keysize field
  1305.         if (true==bOK) {
  1306.             var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  1307.             var sMessage;
  1308.             if (isNaN(nKeySize)) {
  1309.                 sMessage=L_KeySizeNotNumber_ErrorMessage;
  1310.                 bOK=false;
  1311.             } else if (g_nCurTemplateKeySizeMin > g_nCurKeySizeMax) {
  1312.                 sMessage=eval(L_TemplateKeySizeTooBig_ErrorMessage);
  1313.                 bOK = false;
  1314.             } else if (nKeySize < g_nCurKeySizeMin || nKeySize > g_nCurKeySizeMax || 0!=nKeySize%g_nCurKeySizeInc) {
  1315.                 sMessage=eval(L_KeySizeBadNumber_ErrorMessage);
  1316.                 bOK=false;
  1317.             }
  1318.             if (false==bOK) {
  1319.                 alert (sMessage);
  1320.                 document.UIForm.tbKeySize.focus();
  1321.             }
  1322.         }
  1323.  
  1324.         // Check the container name
  1325.         if (true==bOK) {
  1326.             if (document.UIForm.rbKeyGen[1].checked
  1327.                 || (document.UIForm.rbKeyGen[0].checked && document.UIForm.rbGenContName[1].checked)) {
  1328.                 if (""==document.UIForm.tbContainerName.value) {
  1329.                     bOK=false;
  1330.                     alert(L_NoCntnrName_ErrorMessage);
  1331.                     document.UIForm.tbContainerName.focus();
  1332.                 }
  1333.             }
  1334.         }
  1335.  
  1336.         <%If bEnableExportKeyToFile Then%>
  1337.         // Check the exported private key file name
  1338.         if (true==bOK) {
  1339.             if (document.UIForm.rbKeyGen[0].checked 
  1340.                 && document.UIForm.cbMarkKeyExportable.checked 
  1341.                 && document.UIForm.cbExportKeys.checked) {
  1342.                 if (""==document.UIForm.tbExportKeyFile.value) {
  1343.                     bOK=false;
  1344.                     alert(L_NoExportFileName_ErrorMessage);
  1345.                     document.UIForm.tbExportKeyFile.focus();
  1346.                 }
  1347.             }
  1348.         }
  1349.         <%End If%>
  1350.  
  1351.         // Check the saved-request file name
  1352.         if (true==bOK) {
  1353.             if (document.UIForm.cbSaveRequest.checked) {
  1354.                 if (""==document.UIForm.tbSaveReqFile.value) {
  1355.                     bOK=false;
  1356.                     alert(L_NoSaveReqFileName_ErrorMessage);
  1357.                     document.UIForm.tbSaveReqFile.focus();
  1358.                 }
  1359.             }
  1360.         }
  1361.  
  1362.         return bOK;
  1363.     }
  1364.  
  1365.     //----------------------------------------------------------------
  1366.     function SubmitRequest() {
  1367.         g_bSubmitPending=true;
  1368.  
  1369.         // check that the form is filled in
  1370.         spnErrorTxt.style.display='none';
  1371.         spnFixTxt.style.display='none';
  1372.         if (false==validateRequest()) {
  1373.             g_bSubmitPending=false;
  1374.             return;
  1375.         }
  1376.  
  1377.         // show a nice message since request creation can take a while
  1378.         ShowTransientMessage(L_Generating_Message);
  1379.  
  1380.         // Make the message show up on the screen, 
  1381.         // then continue with 'SubmitRequest':
  1382.         // Pause 10 mS before executing phase 2, 
  1383.         // so screen will have time to repaint.
  1384.         setTimeout("SubmitRequestPhase2();", 10); 
  1385.     }
  1386.     function SubmitRequestPhase2() {
  1387.         // continued from above
  1388.  
  1389.         <%If "StandAlone"=sServerType Then%> 
  1390.         //
  1391.         // Stand-Alone Options
  1392.         //
  1393.  
  1394.         // set the extended key usage and certificate request 'friendly type'
  1395.         var nUsageIndex=document.UIForm.lbUsageOID.selectedIndex;
  1396.         var sCertUsage;
  1397.         if ("**"==document.UIForm.lbUsageOID.options[nUsageIndex].value) {
  1398.             sCertUsage=document.UIForm.tbEKUOther.value;
  1399.             document.SubmittedData.FriendlyType.value=eval(L_UserEKUCert_Text);
  1400.         } else {
  1401.             sCertUsage=document.UIForm.lbUsageOID.options[nUsageIndex].value;
  1402.             document.SubmittedData.FriendlyType.value=document.UIForm.lbUsageOID.options[nUsageIndex].text;
  1403.         }
  1404.  
  1405.         <%Else 'Enterprise%>
  1406.         //
  1407.         // Enterprise Options
  1408.         //
  1409.  
  1410.         // get cert template info
  1411.         var lCTEVer = XECT_EXTENSION_V1;
  1412.         var lCTEMajor = 0;
  1413.         var bCTEfMinor = false;
  1414.         var lCTEMinor = 0;
  1415.         var sRealName = getTemplateStringInfo(CTINFO_INDEX_REALNAME, null);
  1416.         var sFriendlyName = getTemplateStringInfo(CTINFO_INDEX_FRIENDLYNAME, null); 
  1417.         var sCTEOID = getTemplateStringInfo(CTINFO_INDEX_EXTOID, null);
  1418.         if ("" == sCTEOID) {
  1419.             //must v1 template, get template name
  1420.             sCTEOID = sRealName;            
  1421.         } else {
  1422.             // v2 template
  1423.             lCTEVer = XECT_EXTENSION_V2;
  1424.             lCTEMajor = getTemplateValueInfo(CTINFO_INDEX_EXTMAJ, null);
  1425.             bCTEfMinor = getTemplateValueInfo(CTINFO_INDEX_EXTFMIN, null);
  1426.             lCTEMinor = getTemplateValueInfo(CTINFO_INDEX_EXTMIN, null);
  1427.         }
  1428.         // set the cert template
  1429.         vbAddCertTypeToRequestEx(lCTEVer, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor);
  1430.         document.SubmittedData.FriendlyType.value=eval(L_TemplateCert_Text);
  1431.  
  1432.         var sCertUsage=""; // ignored
  1433.  
  1434.         <%End If 'StandAlone or Enterprise%> 
  1435.         //
  1436.         // Common
  1437.         //
  1438.  
  1439.         // set the identifying info
  1440.         var sDistinguishedName="";
  1441.         if (""!=document.UIForm.tbCountry.value) {
  1442.             sDistinguishedName+="C=\""+document.UIForm.tbCountry.value.replace(/"/g, "\"\"")   +"\";";
  1443.         }
  1444.         if (""!=document.UIForm.tbState.value) {
  1445.             sDistinguishedName+="S=\""+document.UIForm.tbState.value.replace(/"/g, "\"\"")     +"\";";
  1446.         }
  1447.         if (""!=document.UIForm.tbLocality.value) {
  1448.             sDistinguishedName+="L=\""+document.UIForm.tbLocality.value.replace(/"/g, "\"\"")  +"\";";
  1449.         }
  1450.         if (""!=document.UIForm.tbOrg.value) {
  1451.             sDistinguishedName+="O=\""+document.UIForm.tbOrg.value.replace(/"/g, "\"\"")       +"\";";
  1452.         }
  1453.         if (""!=document.UIForm.tbOrgUnit.value) {
  1454.             sDistinguishedName+="OU=\""+document.UIForm.tbOrgUnit.value.replace(/"/g, "\"\"")   +"\";";
  1455.         }
  1456.         if (""!=document.UIForm.tbEmail.value) {
  1457.             sDistinguishedName+="E=\""+document.UIForm.tbEmail.value.replace(/"/g, "\"\"")     +"\";";
  1458.         }
  1459.         if (""!=document.UIForm.tbCommonName.value) {
  1460.             sDistinguishedName+="CN=\""+document.UIForm.tbCommonName.value.replace(/"/g, "\"\"")+"\";";
  1461.         }
  1462.         <%If "Enterprise"=sServerType Then%> 
  1463.         if (false==isDNNeeded()) {
  1464.             sDistinguishedName="";
  1465.         }
  1466.         <%End If%>
  1467.  
  1468.         // append the local date to the type
  1469.         document.SubmittedData.FriendlyType.value+=" ("+(new Date()).toLocaleString()+")";
  1470.  
  1471.         //
  1472.         // Key Options subheading:
  1473.         //
  1474.  
  1475.         // set the 'SaveCert' flag to install the cert instead of saving
  1476.         document.SubmittedData.SaveCert.value="no";
  1477.              
  1478.         // set the CSP
  1479.         var nCSPIndex=document.UIForm.lbCSP.selectedIndex;
  1480.         XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  1481.         XEnroll.ProviderType=document.UIForm.lbCSP.options[nCSPIndex].value;
  1482.  
  1483.         // set the key size (the upper 16 bits of GenKeyFlags)
  1484.         //  note: this value has already been validated
  1485.         var nKeySize=parseInt(document.UIForm.tbKeySize.value);
  1486.         XEnroll.GenKeyFlags=nKeySize<<16;
  1487.  
  1488.         // set the KeyUsage
  1489.         if (document.UIForm.rbKeyUsage[KEY_USAGE_EXCH].checked) {
  1490.             XEnroll.KeySpec=AT_KEYEXCHANGE;
  1491.             XEnroll.LimitExchangeKeyToEncipherment=true;
  1492.         } else if (document.UIForm.rbKeyUsage[KEY_USAGE_SIG].checked) {
  1493.             XEnroll.KeySpec=AT_SIGNATURE;
  1494.             XEnroll.LimitExchangeKeyToEncipherment=false;
  1495.         } else { // KEY_USAGE_BOTH
  1496.             XEnroll.KeySpec=AT_KEYEXCHANGE;
  1497.             XEnroll.LimitExchangeKeyToEncipherment=false;
  1498.         }
  1499.  
  1500.         // set the 'use existing key set' flag
  1501.         if (document.UIForm.rbKeyGen[0].checked) {
  1502.             XEnroll.UseExistingKeySet=false;
  1503.             if (document.UIForm.rbGenContName[1].checked) {
  1504.                 XEnroll.ContainerName=document.UIForm.tbContainerName.value;
  1505.             }
  1506.  
  1507.             // set 'Strong private key protection'
  1508.             //   note: upper 16 bits already set as key size
  1509.             if (document.UIForm.cbStrongKey.checked) {
  1510.                 XEnroll.GenKeyFlags|=CRYPT_USER_PROTECTED;
  1511.             }
  1512.  
  1513.             // mark the keys as exportable
  1514.             if (document.UIForm.cbMarkKeyExportable.checked) {
  1515.                 XEnroll.GenKeyFlags|=CRYPT_EXPORTABLE;
  1516.  
  1517.                 <%If bEnableExportKeyToFile Then%>
  1518.                 // set the key export file (.pvk) and save the cert instead of installing
  1519.                 if (document.UIForm.cbExportKeys.checked) {
  1520.                     XEnroll.PVKFileName=document.UIForm.tbExportKeyFile.value;
  1521.                     document.SubmittedData.SaveCert.value="yes";
  1522.                 } 
  1523.                 <%End If%>
  1524.             }
  1525.  
  1526.         } else {
  1527.             // set the 'use existing key set' flag
  1528.             XEnroll.UseExistingKeySet=true;
  1529.             XEnroll.ContainerName=document.UIForm.tbContainerName.value;
  1530.         }
  1531.  
  1532.  
  1533.         // place the keys in the local machine store
  1534.         if (document.UIForm.cbLocalMachineStore.checked) {
  1535.  
  1536.             // the keys attached to the dummy request cert go in the local machine store
  1537.             XEnroll.RequestStoreFlags=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  1538.  
  1539.             // used in CryptAcquireContext
  1540.             XEnroll.ProviderFlags=CRYPT_MACHINE_KEYSET;
  1541.  
  1542.             // the keys attached to the final cert also go in the local machine store
  1543.             document.SubmittedData.TargetStoreFlags.value=CERT_SYSTEM_STORE_LOCAL_MACHINE;
  1544.         } else {
  1545.  
  1546.             // the keys attached to the final cert also go in the user store
  1547.             document.SubmittedData.TargetStoreFlags.value=0; // 0=Use default (=user store)
  1548.         }
  1549.  
  1550.         var dwCreateRequestFlag = XECR_CMC;
  1551.         if (document.UIForm.rbRequestFormat[1].checked)
  1552.         {
  1553.             dwCreateRequestFlag = XECR_PKCS10_V2_0;
  1554.         }
  1555.  
  1556.         <%If "Enterprise"=sServerType Then%>
  1557.         //SMIME capabilities
  1558.         XEnroll.EnableSMIMECapabilities = isSMimeCapabilities();
  1559.  
  1560.                 //Key archival
  1561.         if (isTemplateKeyArchival())
  1562.         {
  1563.             var nResult = SetPrivateKeyArchiveCertificate(); //call VB
  1564.             if (0 != nResult)
  1565.             {
  1566.                 handleError(nResult);
  1567.                 return;
  1568.             }
  1569.         }
  1570.         <%End If%>
  1571.  
  1572.         if ("" != document.UIForm.tbFriendlyName.value)
  1573.         {
  1574.             //set friendly name property
  1575.             var CERT_FRIENDLY_NAME_PROP_ID=11;
  1576.             var XECP_STRING_PROPERTY=1;
  1577.             XEnroll.addBlobPropertyToCertificate(CERT_FRIENDLY_NAME_PROP_ID, XECP_STRING_PROPERTY, document.UIForm.tbFriendlyName.value);
  1578.         }
  1579.  
  1580.         //
  1581.         // Additional Options subheading:
  1582.         //
  1583.  
  1584.         // set the hash algorithm     
  1585.         var nHashIndex=document.UIForm.lbHashAlgorithm.selectedIndex;
  1586.         XEnroll.HashAlgID=document.UIForm.lbHashAlgorithm.options[nHashIndex].value;
  1587.  
  1588.         // set any extra attributes
  1589.         var sAttrib=document.UIForm.taAttrib.value;
  1590.         if (sAttrib.lastIndexOf("\r\n")!=sAttrib.length-2 && sAttrib.length>0) {
  1591.             sAttrib=sAttrib+"\r\n";
  1592.         }
  1593.  
  1594.         // for interop debug purposes
  1595.         sAttrib+="UserAgent:<%=Request.ServerVariables("HTTP_USER_AGENT")%>\r\n";
  1596.  
  1597.         document.SubmittedData.CertAttrib.value=sAttrib;
  1598.  
  1599.         // we are submitting a new request
  1600.         document.SubmittedData.Mode.value='newreq';
  1601.  
  1602.         // 
  1603.         // Create the request
  1604.         //
  1605.  
  1606.         var nResult;
  1607.         var HRESULT_ERROR_CANCELLED=0x800704c7;
  1608.         var SCARD_W_CANCELLED_BY_USER=0x8010006e;
  1609.         var PVK_HELPER_PASSWORD_CANCEL=0x80097004;
  1610.  
  1611.         if (document.UIForm.cbSaveRequest.checked) {
  1612.  
  1613.             // build and save the certificate request
  1614.             var sSaveReqFile=document.UIForm.tbSaveReqFile.value;
  1615.             nResult=CreateAndSaveRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage, sSaveReqFile); // ask VB to do it, since it can handle errors
  1616.  
  1617.         } else {
  1618.             // build the certificate request
  1619.             nResult=CreateRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage); // ask VB to do it, since it can handle errors
  1620.         }
  1621.         if (0 == nResult)
  1622.         {
  1623.             //always get thumbprint in case of pending
  1624.             document.SubmittedData.ThumbPrint.value=XEnroll.ThumbPrint;
  1625.         }
  1626.  
  1627.         // hide the message box
  1628.         HideTransientMessage();
  1629.  
  1630.         // reset XEnroll so the user can select a different CSP, etc.
  1631.         XEnroll.reset();
  1632.         // however, make sure it still matches the UI.
  1633.         XEnroll.ProviderName=document.UIForm.lbCSP.options[nCSPIndex].text;
  1634.         XEnroll.ProviderType=document.UIForm.lbCSP.options[nCSPIndex].value;
  1635.  
  1636.         // deal with an error if there was one
  1637.         if (0!=nResult) {
  1638.             g_bSubmitPending=false;
  1639.             if (0==(SCARD_W_CANCELLED_BY_USER^nResult) ||
  1640.                 0==(PVK_HELPER_PASSWORD_CANCEL^nResult))
  1641.             {
  1642.                 //cancelled
  1643.                 nResult=0;
  1644.                 return;
  1645.             }
  1646.  
  1647.  
  1648.             <%If "Enterprise"=sServerType Then%>
  1649.             if (isTemplateKeyArchival() && !document.UIForm.cbMarkKeyExportable.checked) 
  1650.             {
  1651.                 //they've tried to create an archivable key
  1652.                 handleError2(nResult, L_SugCauseCryptArchivableNotSupp_ErrorMessage);                     
  1653.             } else {
  1654.                 // use the regular error handling
  1655.                 handleError(nResult);
  1656.             }
  1657.             <%Else%>
  1658.             // just use the regular error handling in the standalone case
  1659.             handleError(nResult);        
  1660.             <%End If%>
  1661.  
  1662.             return;
  1663.         }
  1664.  
  1665.         // check for special "no submit" case
  1666.         if (document.UIForm.cbSaveRequest.checked) {
  1667.  
  1668.             // just inform the user that it went OK, but don't submit
  1669.             alert(L_RequestSaved_Message);
  1670.             g_bSubmitPending=false;
  1671.  
  1672.         } else {
  1673.  
  1674.             // put up a new wait message
  1675.             ShowTransientMessage(L_Waiting_Message);
  1676.  
  1677.             // Submit the cert request and move forward in the wizard
  1678.             document.SubmittedData.submit();
  1679.         }
  1680.     }
  1681.  
  1682.     
  1683.     //----------------------------------------------------------------
  1684.     function handleError(nResult) {
  1685.         handleError2(nResult, 0);
  1686.     }
  1687.  
  1688.     //----------------------------------------------------------------
  1689.     function handleError2(nResult, sSugCauseIN) { 
  1690.         var sSugCause=L_SugCauseNone_ErrorMessage;
  1691.         var sErrorName=L_ErrNameUnknown_ErrorMessage;
  1692.         // analyze the error - funny use of XOR ('^') because obvious choice '==' doesn't work
  1693.         if (0==(0x80090008^nResult)) {
  1694.             sErrorName="NTE_BAD_ALGID";
  1695.             sSugCause=L_SugCauseBadSetting2_ErrorMessage;
  1696.         } else if (0==(0x80090016^nResult)) {
  1697.             sErrorName="NTE_BAD_KEYSET";
  1698.             if (document.UIForm.rbKeyGen[0].checked) {
  1699.                 sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1700.             } else {
  1701.                 sSugCause=L_SugCauseBadKeyContainer_ErrorMessage;
  1702.             }
  1703.         } else if (0==(0x80090019^nResult)) {
  1704.             sErrorName="NTE_KEYSET_NOT_DEF";
  1705.             sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1706.         } else if (0==(0x80090020^nResult)) {
  1707.             sErrorName="NTE_FAIL";
  1708.             sSugCause=L_SugCauseBadCSP_ErrorMessage;
  1709.         } else if (0==(0x80090023^nResult)) {
  1710.             sErrorName="NTE_TOKEN_KEYSET_STORAGE_FULL";
  1711.             sSugCause=L_SugCauseKeysetFull_ErrorMessage;
  1712.         } else if (0==(0x80090009^nResult)) {
  1713.             sErrorName="NTE_BAD_FLAGS";
  1714.             sSugCause=L_SugCauseBadSetting2_ErrorMessage;
  1715.         } else if (0==(0x8009000F^nResult)) {
  1716.             sErrorName="NTE_EXISTS";
  1717.             sSugCause=L_SugCauseExistKeyContainer_ErrorMessage;
  1718.         } else if (0==(0x80092002^nResult)) {
  1719.             sErrorName="CRYPT_E_BAD_ENCODE";
  1720.             //sSugCause="";
  1721.         } else if (0==(0x80092022^nResult)) {
  1722.             sErrorName="CRYPT_E_INVALID_IA5_STRING";
  1723.             sSugCause=L_SugCauseBadChar_ErrorMessage;
  1724.         } else if (0==(0x80092023^nResult)) {
  1725.             sErrorName="CRYPT_E_INVALID_X500_STRING";
  1726.             sSugCause=L_SugCauseBadChar_ErrorMessage;
  1727.         } else if (0==(0x80070003^nResult)) {
  1728.             sErrorName="ERROR_PATH_NOT_FOUND";
  1729.             sSugCause=L_SugCauseBadFileName_ErrorMessage;
  1730.         } else if (0==(0x80070103^nResult)) {
  1731.             sErrorName="ERROR_NO_MORE_ITEMS";
  1732.             sSugCause=L_SugCauseBadHash_ErrorMessage;
  1733.         } else if (0==(0x8007007B^nResult)) {
  1734.             sErrorName="ERROR_INVALID_NAME";
  1735.             sSugCause=L_SugCauseBadFileName_ErrorMessage;
  1736.         } else if (0==(0x80070015^nResult)) {
  1737.             sErrorName="ERROR_NOT_READY";
  1738.             sSugCause=L_SugCauseBadDrive_ErrorMessage;
  1739.         } else if (0==(0x8007007F^nResult)) {
  1740.             sErrorName="ERROR_PROC_NOT_FOUND";
  1741.             sSugCause=L_DownLevelClients_ErrorMessage;
  1742.         } else if (0==(0x800704C7^nResult)) { 
  1743.             sErrorNamge="ERROR_CANCELLED";
  1744.             sSugCause=L_SugCauseCancelled_ErrorMessage;
  1745.         } else if (0==(0x80100006^nResult)) {
  1746.             sErrorName = "SCARD_E_NO_MEMORY";
  1747.             sSugCause = L_SCARD_E_NOMEMORYMSG_ErrorMessage;
  1748.         } else if (0==(0x80100007^nResult)) {
  1749.             sErrorName = "SCARD_F_WAITED_TOO_LONG";
  1750.             sSugCause = L_SCARD_F_WAITEDTOOLONG_ErrorMessage;
  1751.         } else if (0==(0x80100008^nResult)) {
  1752.             sErrorName = "SCARD_E_INSUFFICIENT_BUFFER";
  1753.             sSugCause = L_SCARD_E_INSUFFICIENTBUFFER_ErrorMessage;
  1754.         } else if (0==(0x80100009^nResult)) {
  1755.             sErrorName = "SCARD_E_UNKNOWN_READER";
  1756.             sSugCause = L_SCARD_E_UNKNOWNREADER_ErrorMessage;
  1757.         } else if (0==(0x8010000C^nResult)) {
  1758.             sErrorName = "SCARD_E_NO_SMARTCARD";
  1759.             sSugCause = L_SCARD_E_NOSMARTCARD_ErrorMessage;
  1760.         } else if (0==(0x8010000D^nResult)) {
  1761.             sErrorName = "SCARD_E_UNKNOWN_CARD";
  1762.             sSugCause = L_SCARD_E_UNKNOWNCARD_ErrorMessage;
  1763.         } else if (0==(0x80100010^nResult)) {
  1764.             sErrorName = "SCARD_E_NOT_READY";
  1765.             sSugCause = L_SCARD_E_NOTREADY_ErrorMessage;
  1766.         } else if (0==(0x80100013^nResult)) {
  1767.             sErrorName = "SCARD_F_COMM_ERROR";
  1768.             sSugCause = L_SCARD_F_COMMERROR_ErrorMessage;
  1769.         } else if (0==(0x8010001D^nResult)) {
  1770.             sErrorName = "SCARD_E_NO_SERVICE";
  1771.             sSugCause = L_SCARD_E_NOSERVICE_ErrorMessage;
  1772.         } else if (0==(0x8010001E^nResult)) {
  1773.             sErrorName = "SCARD_E_SERVICE_STOPPED";
  1774.             sSugCause = L_SCARD_E_SERVICESTOPPED_ErrorMessage;
  1775.         } else if (0==(0x8010002E^nResult)) {
  1776.             sErrorName = "SCARD_E_NO_READERS_AVAILABLE";
  1777.             sSugCause = L_SCARD_E_NOREADERSAVAILABLE_ErrorMessage;
  1778.         } else if (0==(0x8010002F^nResult)) {
  1779.             sErrorName = "SCARD_E_COMM_DATA_LOST";
  1780.             sSugCause = L_SCARD_E_COMMDATALOST_ErrorMessage;
  1781.         } else if (0==(0x80100030^nResult)) {
  1782.             sErrorName = "SCARD_E_NO_KEY_CONTAINER";
  1783.             sSugCause = L_SCARD_E_NOKEYCONTAINER_ErrorMessage;
  1784.         } else if (0==(0x80100067^nResult)) {
  1785.             sErrorName = "SCARD_W_UNPOWERED_CARD";
  1786.             sSugCause = L_SCARD_W_UNPOWEREDCARD_ErrorMessage;
  1787.         } else if (0==(0x80100069^nResult)) {
  1788.             sErrorName = "SCARD_W_REMOVED_CARD";
  1789.             sSugCause = L_SCARD_W_REMOVEDCARD_ErrorMessage;
  1790.         } else if (0==(0x8010006B^nResult)) {
  1791.             sErrorName = "SCARD_W_WRONG_CHV";
  1792.             sSugCause = L_SCARD_W_WRONGCHV_ErrorMessage;
  1793.         } else if (0==(0x8010006C^nResult)) {
  1794.             sErrorName = "SCARD_W_CHV_BLOCKED";
  1795.             sSugCause = L_SCARD_W_CHVBLOCKED_ErrorMessage;
  1796.         } else if (0==(0x8010006D^nResult)) {
  1797.             sErrorName = "SCARD_W_EOF";
  1798.             sSugCause = L_SCARD_W_EOF_ErrorMessage;
  1799.         } else if (0==(0x8010006E^nResult)) {
  1800.             sErrorName = "SCARD_W_CANCELLED_BY_USER";
  1801.             sSugCause = L_SCARD_W_CANCELLEDBYUSER_ErrorMessage;
  1802.         } else if (0==(0x8010006F^nResult)) {
  1803.             sErrorName = "SCARD_W_CARD_NOT_AUTHENTICATED";
  1804.             sSugCause = L_SCARD_W_CARDNOTAUTHENTICATED_ErrorMessage;
  1805.         } else if (0==(0x80090024^nResult)) {
  1806.             sErrorName = "NTE_TEMPORARY_PROFILE";
  1807.             sSugCause = L_SugCauseNoProfile_ErrorMessage;
  1808.         } else if (0==(0xFFFFFFFF^nResult)) {
  1809.             sErrorName=L_ErrNameNoFileName_ErrorMessage;
  1810.             sSugCause=L_SugCauseNoFileName_ErrorMessage;
  1811.         } else if (0==(0x800B010A^nResult)) {
  1812.             sErrorName = "CERT_E_CHAINING";
  1813.             sSugCause=L_SugCauseCAExSignerNotFound_ErrorMessage;
  1814.         } else if (0==(0x800B0109^nResult)) {
  1815.             sErrorName = "CERT_E_UNTRUSTEDROOT";
  1816.             sSugCause=L_SugCauseCAExNotTrusted_ErrorMessage;
  1817.         } else if (0==(0x8000FFFF^nResult)) {
  1818.             sErrorName="E_UNEXPECTED";
  1819.         } else if (0==(0x00000046^nResult)) {
  1820.             sErrorName=L_ErrNamePermissionDenied_ErrorMessage;
  1821.             if (document.UIForm.cbSaveRequest.checked) {
  1822.                 sSugCause=L_SugCausePermissionToWrite_ErrorMessage;
  1823.             }
  1824.             else {
  1825.                 sSugCause=L_SugCausePermissionToWrite_ErrorMessage;
  1826.             }
  1827.         }
  1828.         
  1829.         // modify the document text and appearance to show the error message
  1830.         spnErrorNum.innerText="0x"+toHex(nResult)+" - "+sErrorName;
  1831.          if (0 == sSugCauseIN) { 
  1832.             spnErrorMsg.innerText=sSugCause;
  1833.         } else { 
  1834.             spnErrorMsg.innerText=sSugCauseIN;
  1835.         }
  1836.         spnFixTxt.style.display='none';
  1837.         spnErrorTxt.style.display='';
  1838.  
  1839.         // back to the top so the messages show
  1840.         window.scrollTo(0,0);
  1841.     }
  1842.  
  1843.  
  1844. </Script> 
  1845. <Script Language="VBScript">
  1846.     ' The current CA exchange certificate
  1847.     Public sCAExchangeCert
  1848.     sCAExchange=""
  1849. <%=sCAExchangeCert%>
  1850.  
  1851.     '-----------------------------------------------------------------
  1852.     ' call XEnroll to create a request, since javascript has no error handling
  1853.     Function CreateRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage)
  1854.         On Error Resume Next
  1855.         XEnroll.ReuseHardwareKeyIfUnableToGenNew=False
  1856.         document.SubmittedData.CertRequest.value= _
  1857.             XEnroll.CreateRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage)
  1858.         CreateRequest=Err.Number
  1859.     End Function
  1860.  
  1861.     '-----------------------------------------------------------------
  1862.     ' call XEnroll to create and save a request, since javascript has no error handling
  1863.     Function CreateAndSaveRequest(dwCreateRequestFlag, sDistinguishedName, sCertUsage, sSaveReqFile)
  1864.         On Error Resume Next
  1865.         XEnroll.ReuseHardwareKeyIfUnableToGenNew=False
  1866.         XEnroll.createFileRequest dwCreateRequestFlag, sDistinguishedName, sCertUsage, sSaveReqFile
  1867.         CreateAndSaveRequest=Err.Number
  1868.     End Function
  1869.  
  1870.     '----------------------------------------------------------------
  1871.     ' handle a change in the current CSP, since javascript has no error handling
  1872.     Sub UpdateHashAlgList(nProvType)
  1873.         On Error Resume Next
  1874.         Dim nIndex, nAlgID, oElem, bList, lCSPType
  1875.         Const CALG_SSL3_SHAMD5=32776
  1876.         Const CALG_MAC=32773
  1877.         Const CALG_HMAC=32777
  1878.         Const CALG_MD5=32771
  1879.  
  1880.         'really strange, I can't use nProvType in following If compare
  1881.         'so I have to fetch from xenroll which is the same as nProvType:(
  1882.         lCSPType=XEnroll.ProviderType
  1883.  
  1884.         ' clear the list
  1885.         While document.UIForm.lbHashAlgorithm.length>0
  1886.             document.UIForm.lbHashAlgorithm.options.remove(0)
  1887.         Wend
  1888.  
  1889.         ' retrieve the list from XEnroll
  1890.         nIndex=0
  1891.         Do 
  1892.             ' get the next AlgID
  1893.             nAlgID=XEnroll.EnumAlgs(nIndex, ALG_CLASS_HASH)
  1894.             If 0<>Err.Number Then 
  1895.                 ' no more algs
  1896.                 Err.Clear
  1897.                 Exit Do
  1898.             End If
  1899.  
  1900.             bList = True
  1901.  
  1902.             'GetAlgName is not cheap, try to reduce the call, check ID to filter out some unwanted hash
  1903.  
  1904.             'can't use the following hash
  1905.             If CALG_SSL3_SHAMD5=nAlgID Or CALG_MAC=nAlgID Or CALG_HMAC=nAlgID Then
  1906.                 bList = False
  1907.             End If
  1908.  
  1909.             'DSS or DH won't work with MD5
  1910.             If CALG_MD5=nAlgID And PROV_DSS=lCSPType Or CALG_MD5=nAlgID And PROV_DSS_DH=lCSPType or CALG_MD5=nAlgID And PROV_DH_SCHANNEL=lCSPType Then
  1911.                 bList = False
  1912.             End If
  1913.  
  1914.             If True=bList Then
  1915.                 ' get the corresponding name and create an option in the list box
  1916.                 sName=XEnroll.GetAlgName(nAlgID)
  1917.                 Set oElem=document.createElement("Option")
  1918.                 oElem.text=sName
  1919.                 oElem.value=nAlgID
  1920.                 document.UIForm.lbHashAlgorithm.options.add(oElem)
  1921.             End If
  1922.             nIndex=nIndex+1
  1923.  
  1924.         Loop ' <- End alg enumeration loop
  1925.  
  1926.         ' make sure the first one is selectd
  1927.         document.UIForm.lbHashAlgorithm.selectedIndex=0
  1928.  
  1929.     End Sub
  1930.  
  1931.     '----------------------------------------------------------------
  1932.     ' call XEnroll to get the key length, since javascript has no error handling
  1933.     Function MyGetKeyLen(nSizeSpec, bExchange)
  1934.         On Error Resume Next
  1935.         Dim nKeySpec
  1936.         If True=bExchange Then
  1937.             nKeySpec=XEKL_KEYSPEC_KEYX
  1938.         Else
  1939.             nKeySpec=XEKL_KEYSPEC_SIG
  1940.         End If
  1941.         MyGetKeyLen=XEnroll.GetKeyLenEx(nSizeSpec, nKeySpec)
  1942.         If 0<>Err.Number Then
  1943.             If XEKL_KEYSIZE_MIN=nSizeSpec Then
  1944.                 MyGetKeyLen=KEY_LEN_MIN_DEFAULT
  1945.             ElseIf XEKL_KEYSIZE_MAX=nSizeSpec Then
  1946.                 MyGetKeyLen=KEY_LEN_MAX_DEFAULT
  1947.             ElseIf XEKL_KEYSIZE_DEFAULT=nSizeSpec Then
  1948.                 MyGetKeyLen=KEY_LEN_MY_DEFAULT  'try 1024
  1949.             Else 'assume XEKL_KEYSIZE_INC=nSizeSpec
  1950.                 MyGetKeyLen=KEY_LEN_INC_DEFAULT
  1951.             End If
  1952.         End If
  1953.         If XEKL_KEYSIZE_INC=nSizeSpec And 0=MyGetKeyLen Then
  1954.             MyGetKeyLen=KEY_LEN_INC_DEFAULT
  1955.         End If
  1956.     End Function
  1957.  
  1958.     '----------------------------------------------------
  1959.     ' set a certificate for key archive
  1960.     Function SetPrivateKeyArchiveCertificate()
  1961.         On Error Resume Next
  1962.  
  1963.         XEnroll.PrivateKeyArchiveCertificate=sCAExchange
  1964.     SetPrivateKeyArchiveCertificate = Err.Number
  1965.     End Function
  1966.  
  1967.     '----------------------------------------------------
  1968.     ' set request template extension
  1969.     Function vbAddCertTypeToRequestEx(lCTEVer, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor)
  1970.         On Error Resume Next
  1971.  
  1972.         XEnroll.addCertTypeToRequestEx lCTEVer, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor
  1973.         If 0 <> Err.Number Then
  1974.             'possible on downlevel not supporting v2 encoding, change to v1
  1975.             XEnroll.addCertTypeToRequestEx XECT_EXTENSION_V1, sCTEOID, lCTEMajor, bCTEfMinor, lCTEMinor
  1976.         End If
  1977.         vbAddCertTypeToRequestEx=Err.Number
  1978.     End Function
  1979.  
  1980. </Script> 
  1981.  
  1982. <%End If 'bFailed%>
  1983.  
  1984. </Body>
  1985. </HTML>
  1986.